commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1413916 - in /commons/proper/math/trunk/src: changes/changes.xml main/java/org/apache/commons/math3/util/FastMath.java test/java/org/apache/commons/math3/util/FastMathTest.java
Date Mon, 26 Nov 2012 23:02:30 GMT
Author: erans
Date: Mon Nov 26 23:02:29 2012
New Revision: 1413916

URL: http://svn.apache.org/viewvc?rev=1413916&view=rev
Log:
MATH-904.
Fixed wrong assumption in "pow" method.

Modified:
    commons/proper/math/trunk/src/changes/changes.xml
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/FastMath.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/FastMathTest.java

Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1413916&r1=1413915&r2=1413916&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Mon Nov 26 23:02:29 2012
@@ -52,6 +52,9 @@ If the output is not quite correct, chec
   <body>
     <release version="3.1" date="TBD" description="
 ">
+      <action dev="erans" type="fix" issue="MATH-904" due-to="Jeff Hain">
+        Fixed "pow" method in class "FastMath".
+      </action>
       <action dev="erans" type="update" issue="MATH-902" due-to="Bruce A. Johnson">
         Created a "maximum number of iterations" stopping criterion in the
         convergence checkers (package "o.a.c.m.optimization") that allows the

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/FastMath.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/FastMath.java?rev=1413916&r1=1413915&r2=1413916&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/FastMath.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/FastMath.java Mon
Nov 26 23:02:29 2012
@@ -309,6 +309,8 @@ public class FastMath {
 
     /** 2^52 - double numbers this large must be integral (no fraction) or NaN or Infinite
*/
     private static final double TWO_POWER_52 = 4503599627370496.0;
+    /** 2^53 - double numbers this large must be even. */
+    private static final double TWO_POWER_53 = 2 * TWO_POWER_52;
 
     /** Constant: {@value}. */
     private static final double F_1_3 = 1d / 3d;
@@ -1537,7 +1539,7 @@ public class FastMath {
         /* Handle special case x<0 */
         if (x < 0) {
             // y is an even integer in this case
-            if (y >= TWO_POWER_52 || y <= -TWO_POWER_52) {
+            if (y >= TWO_POWER_53 || y <= -TWO_POWER_53) {
                 return pow(-x, y);
             }
 

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/FastMathTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/FastMathTest.java?rev=1413916&r1=1413915&r2=1413916&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/FastMathTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/FastMathTest.java
Mon Nov 26 23:02:29 2012
@@ -158,6 +158,16 @@ public class FastMathTest {
     }
 
     @Test
+    public void testMath904() {
+        final double x = -1;
+        final double y = (5 + 1e-15) * 1e15;
+        Assert.assertEquals(Math.pow(x, y),
+                            FastMath.pow(x, y), 0);
+        Assert.assertEquals(Math.pow(x, -y),
+                            FastMath.pow(x, -y), 0);
+    }
+
+    @Test
     public void testMath905LargePositive() {
         final double start = StrictMath.log(Double.MAX_VALUE);
         final double endT = StrictMath.sqrt(2) * StrictMath.sqrt(Double.MAX_VALUE);



Mime
View raw message