Project

Profile

Help

divide by zero misreported?

Added by Anonymous about 19 years ago

Legacy ID: #3065874 Legacy Poster: Howard Katz (howardk)

Shouldn't this query: 1.0e0 idiv 0 raise a divide-by-zero error, FOAR0001? Instead it raises a validation error, "FORG0001: Cannot convert double infinity to an integer". (Double infinity? I have enough trouble understanding single infinity. ;) Am I misreading the FandO spec on op:numeric-integer-divide() ? The writeup indicates that the function takes arguments of type xs:numeric, not xs:integer. I note that several other vendors report something along the lines of "arguments don't match signature" or "integer arguments required", so maybe I've got it wrong? Howard


Replies (1)

RE: divide by zero misreported? - Added by Anonymous about 19 years ago

Legacy ID: #3066071 Legacy Poster: Michael Kay (mhkay)

The idiv operator, like other numeric operators, starts by promoting one operand to the type of the other. In this case one operand is a double, so it promotes the other (an integer) to a double. It then does a division using double arithmetic: dividing the double value 1 by the double value 0 returns the double value +INF (which the error message rather clumsily calls "double infinity"). It then, under the rules of the idiv operator, attempts to convert the result to an integer, and this conversion fails. There was a time when the spec required the operands of idiv to be integers, but this is no longer the case. The spec does say "If the divisor is zero, then an error is raised [err:FOAR0001]." There's room for debate on how normative that is. Section 2.3 of the XPath book gives implementations a lot of latitude to evaluate expressions in a different way from that described, even when this results in different error behavior. However, I think it would be more friendly in this case to raise FOAR0001, and will change the code to do so. Michael Kay

    (1-1/1)

    Please register to reply