aherbert commented on code in PR #349:
URL: https://github.com/apache/commons-math/pull/349#discussion_r4490012985


##########
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:
   Please change all cases of (x + x) to 2 * x. Thanks.



-- 
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]

Reply via email to