Bug / Issue Tracking Service
Bugzilla – Bug 6316
[FO] An error should be raised if second argument to op:numeric-integer-divide is INF or -INF
Last modified: 2009-01-28 20:47:23 UTC
The third paragraph of section 6.2.6 of F&O states, "If the divisor is (positive or negative) zero, then an error is raised [err:FOAR0001]. If either operand is NaN or if $arg1 is INF or -INF then an error is raised [err:FOAR0002]." I think we need to prohibit the second operand from being positive or negative infinity as well. If $a is finite, but $b is not finite, there is no value of type xs:integer that could be delivered as the result of ($a idiv $b) so that the following relation is true. (($a idiv $b) * $b) + ($a mod $b) = $a I believe the second sentence should read, "If either operand is NaN, positive infinity or negative infinity, then an error is raised [err:FOAR0002]."
I would suggest a different fix fro this problem. In our Recommendation we said: "If the dividend, $arg1, is not evenly divided by the divisor, $arg2, then the quotient is the xs:integer value obtained, ignoring (truncating) any remainder that results from the division (that is, no rounding is performed). Thus, the semantics " $a idiv $b " are equivalent to " ($a div $b) cast as xs:integer " except for error situations." I believe that this leads us to having xs:float("4") idiv xs:float("INF") return 0. Our editors draft of F&O 1.1/2.1, reflecting our resolution of Bug #6212, says: "If the divisor is (positive or negative) zero, then an error is raised [err:FOAR0001]. If either operand is NaN or if $arg1 is INF or -INF then an error is raised [err:FOAR0002]. Otherwise, subject to limits of precision and overflow/underflow conditions, the result is the largest (furthest from zero) xs:integer value $N such that fn:abs($N * $arg2) le fn:abs($arg1) and fn:compare($N * $arg2, 0) eq fn:compare($arg1, 0)." There is no value of $N, where $arg1 is not NaN, INF, or -INF and $arg2 is INF, that satisfies the expression in the second paragraph (remembering that 0 * INF is NaN and NaN le any value is false). I believe that we should change the first paragraph to say: "If the divisor is (positive or negative) zero, then an error is raised [err:FOAR0001]. If either operand is NaN or if $arg1 is INF or -INF then an error is raised [err:FOAR0002]. [Insert: If $arg2 is INF or -INF, then the result is 0.]"
Decided that the result of A idiv INF should be zero. This technically needs no changes to the text, except possibly for clarification.
Erratum E33 has been drafted to clarify that when the second argument is INF or -INF, the idiv operator returns zero. I am marking this bug as fixed, if you agree please mark it closed.
I agree with the resolution.