Bug #4424
closedArithmetic with large integers
0%
Description
Test case op-numeric-subtractpint2args-3
The result of 52704602390610034 - 52704602390610033
is returned as 0 rather than 1.
The incorrect logic is in Calculator.js:
"i-i": function (lhs, rhs) {
const x = lhs.toNumber() - rhs.toNumber();
return isSafeInteger(x) ? INT.fromNumber(x) : INT.fromBig(Big(lhs.toBig().minus(rhs.toBig())));
Here lhs.toNumber()
and rhs.toNumber()
both return the nearest float; the result of the subtraction is zero, which is a safe integer, so it is returned without further checking.
Although this is most likely to happen with a subtraction, the same problem applies to all the integer operations.
Updated by Michael Kay almost 5 years ago
Also noted, the logic for XdmDecimal.compareTo()
seems to be wrong. I don't have a test case for this, but the path
if (other.toDouble) {
return this.value - other.toDouble().value;
makes no sense because (a) this.value is a Big
, while (b) other.toDouble().value returns a JS Number
.
Updated by Michael Kay over 4 years ago
- Status changed from New to Closed
- Fixed in JS Release set to Saxon-JS 2.0
This (both problems) appears to have been fixed in Saxon-JS 2.0
Please register to edit this issue
Also available in: Atom PDF Tracking page