You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oe...@apache.org on 2015/11/05 21:26:17 UTC

[1/4] [math] fixed some typos in comments

Repository: commons-math
Updated Branches:
  refs/heads/MATH_3_X fff5c35b2 -> 8aecb842d
  refs/heads/master 23a87ac13 -> a94ff90ab


fixed some typos in comments

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/793e9df0
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/793e9df0
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/793e9df0

Branch: refs/heads/master
Commit: 793e9df0436cefdbf523bba70ac621493ce9e649
Parents: 23a87ac
Author: Otmar Ertl <ot...@gmail.com>
Authored: Thu Nov 5 20:34:15 2015 +0100
Committer: Otmar Ertl <ot...@gmail.com>
Committed: Thu Nov 5 20:34:15 2015 +0100

----------------------------------------------------------------------
 src/main/java/org/apache/commons/math4/util/FastMath.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/793e9df0/src/main/java/org/apache/commons/math4/util/FastMath.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/util/FastMath.java b/src/main/java/org/apache/commons/math4/util/FastMath.java
index 12368a5..3d6d27d 100644
--- a/src/main/java/org/apache/commons/math4/util/FastMath.java
+++ b/src/main/java/org/apache/commons/math4/util/FastMath.java
@@ -938,13 +938,13 @@ public class FastMath {
 
         /* epsilon is the difference in x from the nearest multiple of 2^-10.  It
          * has a value in the range 0 <= epsilon < 2^-10.
-         * Do the subtraction from x as the last step to avoid possible loss of percison.
+         * Do the subtraction from x as the last step to avoid possible loss of precision.
          */
         final double epsilon = x - (intVal + intFrac / 1024.0);
 
         /* Compute z = exp(epsilon) - 1.0 via a minimax polynomial.  z has
        full double precision (52 bits).  Since z < 2^-10, we will have
-       62 bits of precision when combined with the contant 1.  This will be
+       62 bits of precision when combined with the constant 1.  This will be
        used in the last addition below to get proper rounding. */
 
         /* Remez generated polynomial.  Converges on the interval [0, 2^-10], error


[3/4] [math] fixed some typos in comments

Posted by oe...@apache.org.
fixed some typos in comments

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/69c83683
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/69c83683
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/69c83683

Branch: refs/heads/MATH_3_X
Commit: 69c83683fd59429a71009c693b6450febdfe8291
Parents: fff5c35
Author: Otmar Ertl <ot...@gmail.com>
Authored: Thu Nov 5 21:16:44 2015 +0100
Committer: Otmar Ertl <ot...@gmail.com>
Committed: Thu Nov 5 21:16:44 2015 +0100

----------------------------------------------------------------------
 src/main/java/org/apache/commons/math3/util/FastMath.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/69c83683/src/main/java/org/apache/commons/math3/util/FastMath.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/util/FastMath.java b/src/main/java/org/apache/commons/math3/util/FastMath.java
index 25419d1..161ad6c 100644
--- a/src/main/java/org/apache/commons/math3/util/FastMath.java
+++ b/src/main/java/org/apache/commons/math3/util/FastMath.java
@@ -938,13 +938,13 @@ public class FastMath {
 
         /* epsilon is the difference in x from the nearest multiple of 2^-10.  It
          * has a value in the range 0 <= epsilon < 2^-10.
-         * Do the subtraction from x as the last step to avoid possible loss of percison.
+         * Do the subtraction from x as the last step to avoid possible loss of precision.
          */
         final double epsilon = x - (intVal + intFrac / 1024.0);
 
         /* Compute z = exp(epsilon) - 1.0 via a minimax polynomial.  z has
        full double precision (52 bits).  Since z < 2^-10, we will have
-       62 bits of precision when combined with the contant 1.  This will be
+       62 bits of precision when combined with the constant 1.  This will be
        used in the last addition below to get proper rounding. */
 
         /* Remez generated polynomial.  Converges on the interval [0, 2^-10], error


[2/4] [math] MATH-1269: fixed FastMath.exp returning NaN for non-NaN arguments

Posted by oe...@apache.org.
MATH-1269: fixed FastMath.exp returning NaN for non-NaN arguments

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/a94ff90a
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/a94ff90a
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/a94ff90a

Branch: refs/heads/master
Commit: a94ff90ab6cd2d92ccb2eb1fd7913b4e5256f02b
Parents: 793e9df
Author: Otmar Ertl <ot...@gmail.com>
Authored: Thu Nov 5 20:37:27 2015 +0100
Committer: Otmar Ertl <ot...@gmail.com>
Committed: Thu Nov 5 21:09:38 2015 +0100

----------------------------------------------------------------------
 src/changes/changes.xml                                     | 3 +++
 src/main/java/org/apache/commons/math4/util/FastMath.java   | 7 +++++++
 .../java/org/apache/commons/math4/util/FastMathTest.java    | 9 +++++++++
 3 files changed, 19 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/a94ff90a/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 022bcf0..9c20d22 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
     </release>
 
     <release version="4.0" date="XXXX-XX-XX" description="">
+      <action dev="oertl" type="fix" issue="MATH-1269"> <!-- backported to 3.6 -->
+        Fixed FastMath.exp that potentially returned NaN for non-NaN argument.
+      </action>
      <action dev="luc" type="add"> <!-- backported to 3.6 -->
        Added a nth order Brent solver for general real fields, replacing the former
        solver that was restricted to Dfp fields only.

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a94ff90a/src/main/java/org/apache/commons/math4/util/FastMath.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/util/FastMath.java b/src/main/java/org/apache/commons/math4/util/FastMath.java
index 3d6d27d..2532c62 100644
--- a/src/main/java/org/apache/commons/math4/util/FastMath.java
+++ b/src/main/java/org/apache/commons/math4/util/FastMath.java
@@ -968,6 +968,13 @@ public class FastMath {
        much larger than the others.  If there are extra bits specified from the
        pow() function, use them. */
         final double tempC = tempB + tempA;
+
+        // If tempC is positive infinite, the evaluation below could result in NaN,
+        // because z could be negative at the same time.
+        if (tempC == Double.POSITIVE_INFINITY) {
+            return Double.POSITIVE_INFINITY;
+        }
+
         final double result;
         if (extra != 0.0) {
             result = tempC*extra*z + tempC*extra + tempC*z + tempB + tempA;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a94ff90a/src/test/java/org/apache/commons/math4/util/FastMathTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/util/FastMathTest.java b/src/test/java/org/apache/commons/math4/util/FastMathTest.java
index ec0d91c..1e93148 100644
--- a/src/test/java/org/apache/commons/math4/util/FastMathTest.java
+++ b/src/test/java/org/apache/commons/math4/util/FastMathTest.java
@@ -217,6 +217,15 @@ public class FastMathTest {
         }
         Assert.assertEquals(0, maxErr, 3);
     }
+    
+    @Test
+    public void testMath1269() {
+        final double arg = 709.8125;
+        final double vM = Math.exp(arg);
+        final double vFM = FastMath.exp(arg);
+        Assert.assertTrue("exp(" + arg + ") is " + vFM + " instead of " + vM,
+                          Precision.equalsIncludingNaN(vM, vFM));
+    }
 
     @Test
     public void testHyperbolicInverses() {


[4/4] [math] MATH-1269: fixed FastMath.exp returning NaN for non-NaN arguments

Posted by oe...@apache.org.
MATH-1269: fixed FastMath.exp returning NaN for non-NaN arguments

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/8aecb842
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/8aecb842
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/8aecb842

Branch: refs/heads/MATH_3_X
Commit: 8aecb842d32464a98eaab722da84902f8126957b
Parents: 69c8368
Author: Otmar Ertl <ot...@gmail.com>
Authored: Thu Nov 5 21:19:35 2015 +0100
Committer: Otmar Ertl <ot...@gmail.com>
Committed: Thu Nov 5 21:19:35 2015 +0100

----------------------------------------------------------------------
 src/changes/changes.xml                                     | 3 +++
 src/main/java/org/apache/commons/math3/util/FastMath.java   | 7 +++++++
 .../java/org/apache/commons/math3/util/FastMathTest.java    | 9 +++++++++
 3 files changed, 19 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/8aecb842/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4a7a846..5bdaf76 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -51,6 +51,9 @@ If the output is not quite correct, check for invisible trailing spaces!
   </properties>
   <body>
     <release version="3.6" date="XXXX-XX-XX" description="">
+      <action dev="oertl" type="fix" issue="MATH-1269">
+        Fixed FastMath.exp that potentially returned NaN for non-NaN argument.
+      </action>
       <action dev="luc" type="add">
         Added a nth order Brent solver for general real fields, replacing the former
         solver that was restricted to Dfp fields only.

http://git-wip-us.apache.org/repos/asf/commons-math/blob/8aecb842/src/main/java/org/apache/commons/math3/util/FastMath.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/util/FastMath.java b/src/main/java/org/apache/commons/math3/util/FastMath.java
index 161ad6c..f30b502 100644
--- a/src/main/java/org/apache/commons/math3/util/FastMath.java
+++ b/src/main/java/org/apache/commons/math3/util/FastMath.java
@@ -968,6 +968,13 @@ public class FastMath {
        much larger than the others.  If there are extra bits specified from the
        pow() function, use them. */
         final double tempC = tempB + tempA;
+
+        // If tempC is positive infinite, the evaluation below could result in NaN,
+        // because z could be negative at the same time.
+        if (tempC == Double.POSITIVE_INFINITY) {
+            return Double.POSITIVE_INFINITY;
+        }
+
         final double result;
         if (extra != 0.0) {
             result = tempC*extra*z + tempC*extra + tempC*z + tempB + tempA;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/8aecb842/src/test/java/org/apache/commons/math3/util/FastMathTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math3/util/FastMathTest.java b/src/test/java/org/apache/commons/math3/util/FastMathTest.java
index aadc4ec..2df5542 100644
--- a/src/test/java/org/apache/commons/math3/util/FastMathTest.java
+++ b/src/test/java/org/apache/commons/math3/util/FastMathTest.java
@@ -215,6 +215,15 @@ public class FastMathTest {
         }
         Assert.assertEquals(0, maxErr, 3);
     }
+    
+    @Test
+    public void testMath1269() {
+        final double arg = 709.8125;
+        final double vM = Math.exp(arg);
+        final double vFM = FastMath.exp(arg);
+        Assert.assertTrue("exp(" + arg + ") is " + vFM + " instead of " + vM,
+                          Precision.equalsIncludingNaN(vM, vFM));
+    }
 
     @Test
     public void testHyperbolicInverses() {