You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
XPath 1.0 defines mod as the remainder from a truncating division, but the parser used Ruby's %, which floors, so the sign followed the right operand. This uses Numeric#remainder instead:
spec
before
after
5 mod -2
1
-1
1
-5 mod 2
-1
1
-1
-0.5 mod 3
-0.5
2.5
-0.5
x mod 0 raised ZeroDivisionError, because Float#% and Float#remainder both raise for a zero divisor. It now returns NaN, like div by zero already returns Infinity or NaN.
The new tests use the spec's examples and fail without the change.
Fixes #385.
XPath 1.0 defines
modas the remainder from a truncating division, but the parser used Ruby's%, which floors, so the sign followed the right operand. This usesNumeric#remainderinstead:5 mod -2-5 mod 2-0.5 mod 3x mod 0raisedZeroDivisionError, becauseFloat#%andFloat#remainderboth raise for a zero divisor. It now returns NaN, likedivby zero already returns Infinity or NaN.The new tests use the spec's examples and fail without the change.