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

[math] Use Double.isNaN rather than x != x in FastMath.

Repository: commons-math
Updated Branches:
  refs/heads/master 35ad94090 -> 903f28059


Use Double.isNaN rather than x != x in FastMath.

Thanks to Benedikt Ritter.

Github: closes #5.
JIRA: MATH-1222

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

Branch: refs/heads/master
Commit: 903f280595099eb6ef4d9d9aabd19dec8511c861
Parents: 35ad940
Author: Luc Maisonobe <lu...@apache.org>
Authored: Sat May 9 22:03:14 2015 +0200
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Sat May 9 22:15:52 2015 +0200

----------------------------------------------------------------------
 pom.xml                                         |  3 +++
 src/changes/changes.xml                         |  3 +++
 .../org/apache/commons/math4/util/FastMath.java | 24 ++++++++++----------
 3 files changed, 18 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/903f2805/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b88cf28..41c01eb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -297,6 +297,9 @@
       <name>S&#233;bastien Riou</name>
     </contributor>
     <contributor>
+      <name>Benedikt Ritter</name>
+    </contributor>
+    <contributor>
       <name>Bill Rossi</name>
     </contributor>
     <contributor>

http://git-wip-us.apache.org/repos/asf/commons-math/blob/903f2805/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 3219f41..6afa831 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="luc" type="fix" issue="MATH-1222" due-to="Benedikt Ritter">
+        Use Double.isNaN rather than x != x in FastMath.
+      </action>
       <action dev="tn" type="fix"> <!-- backported to 3.6 -->
         Fix potential branching errors in "FastMath#pow(double, double)" when
         passing special values, i.e. infinity, due to erroneous JIT optimization.

http://git-wip-us.apache.org/repos/asf/commons-math/blob/903f2805/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 57793bd..cd56192 100644
--- a/src/main/java/org/apache/commons/math4/util/FastMath.java
+++ b/src/main/java/org/apache/commons/math4/util/FastMath.java
@@ -392,7 +392,7 @@ public class FastMath {
      * @return hyperbolic cosine of x
      */
     public static double cosh(double x) {
-      if (x != x) {
+      if (Double.isNaN(x)) {
           return x;
       }
 
@@ -462,7 +462,7 @@ public class FastMath {
      */
     public static double sinh(double x) {
       boolean negate = false;
-      if (x != x) {
+      if (Double.isNaN(x)) {
           return x;
       }
 
@@ -588,7 +588,7 @@ public class FastMath {
     public static double tanh(double x) {
       boolean negate = false;
 
-      if (x != x) {
+      if (Double.isNaN(x)) {
           return x;
       }
 
@@ -991,7 +991,7 @@ public class FastMath {
      * @return exp(x) - 1
      */
     private static double expm1(double x, double hiPrecOut[]) {
-        if (x != x || x == 0.0) { // NaN or zero
+        if (Double.isNaN(x) || x == 0.0) { // NaN or zero
             return x;
         }
 
@@ -1155,7 +1155,7 @@ public class FastMath {
         long bits = Double.doubleToRawLongBits(x);
 
         /* Handle special cases of negative input, and NaN */
-        if (((bits & 0x8000000000000000L) != 0 || x != x) && x != 0.0) {
+        if (((bits & 0x8000000000000000L) != 0 || Double.isNaN(x)) && x != 0.0) {
             if (hiPrec != null) {
                 hiPrec[0] = Double.NaN;
             }
@@ -1462,9 +1462,9 @@ public class FastMath {
 
         if (y == 0.0) {
             return 1.0;
-        } else if (x != x) { // X is NaN
+        } else if (Double.isNaN(x)) {
             return x;
-        } else if (y != y) { // y is NaN
+        } else if (Double.isNaN(y)) {
             return y;
         } else if (x == 0) {
             long bits = Double.doubleToRawLongBits(x);
@@ -2587,7 +2587,7 @@ public class FastMath {
      * @return phase angle of point (x,y) between {@code -PI} and {@code PI}
      */
     public static double atan2(double y, double x) {
-        if (x != x || y != y) {
+        if (Double.isNaN(x) || Double.isNaN(y)) {
             return Double.NaN;
         }
 
@@ -2708,7 +2708,7 @@ public class FastMath {
      * @return arc sine of x
      */
     public static double asin(double x) {
-      if (x != x) {
+      if (Double.isNaN(x)) {
           return Double.NaN;
       }
 
@@ -2784,7 +2784,7 @@ public class FastMath {
      * @return arc cosine of x
      */
     public static double acos(double x) {
-      if (x != x) {
+      if (Double.isNaN(x)) {
           return Double.NaN;
       }
 
@@ -3344,7 +3344,7 @@ public class FastMath {
     public static double floor(double x) {
         long y;
 
-        if (x != x) { // NaN
+        if (Double.isNaN(x)) {
             return x;
         }
 
@@ -3371,7 +3371,7 @@ public class FastMath {
     public static double ceil(double x) {
         double y;
 
-        if (x != x) { // NaN
+        if (Double.isNaN(x)) {
             return x;
         }