insaf021 commented on code in PR #349:
URL: https://github.com/apache/commons-math/pull/349#discussion_r4487264084
##########
commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/AccurateMath.java:
##########
@@ -3710,9 +3710,20 @@ public static double IEEEremainder(final double
dividend, final double divisor)
}
} else {
// we are in the general case
- final double n = AccurateMath.rint(dividend / divisor);
- final double remainder = Double.isInfinite(n) ? 0.0 : dividend -
divisor * n;
- return (remainder == 0) ? AccurateMath.copySign(remainder,
dividend) : remainder;
+ // Reduce |dividend| modulo 2 |divisor| with the exact truncating
remainder
+ // (x is unchanged if 2 |divisor| overflows), then subtract
|divisor| at most
+ // twice to round the quotient to even, as in fdlibm
__ieee754_remainder.
+ // All steps are exact: x + x only overflows when x + x > p holds
anyway.
+ final double p = Math.abs(divisor);
+ double x = Math.abs(dividend) % (p + p);
Review Comment:
Yes, it's the same value. Doubling a double is exact, and 2 * p overflows to
infinity for exactly the same p as p + p, so the overflow path where % leaves x
unchanged behaves as before. Switched in 319201c and AccurateMathTest still
passes. The two x + x comparisons below are the same case if you'd prefer those
as 2 * x as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]