You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2014/06/26 15:08:56 UTC

svn commit: r1605777 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java

Author: erans
Date: Thu Jun 26 13:08:55 2014
New Revision: 1605777

URL: http://svn.apache.org/r1605777
Log:
MATH-1130
Shortcut (in case one of the arguments is NaN). Thanks to Venkatesha Murthy.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java?rev=1605777&r1=1605776&r2=1605777&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java Thu Jun 26 13:08:55 2014
@@ -159,7 +159,7 @@ public class Precision {
      * @since 2.2
      */
     public static boolean equalsIncludingNaN(float x, float y) {
-        return (Float.isNaN(x) && Float.isNaN(y)) || equals(x, y, 1);
+        return (x != x || y != y) ? !(x != x ^ y != y) : equals(x, y, 1);
     }
 
     /**
@@ -255,7 +255,7 @@ public class Precision {
      * @since 2.2
      */
     public static boolean equalsIncludingNaN(float x, float y, int maxUlps) {
-        return (Float.isNaN(x) && Float.isNaN(y)) || equals(x, y, maxUlps);
+        return (x != x || y != y) ? !(x != x ^ y != y) : equals(x, y, maxUlps);
     }
 
     /**
@@ -280,7 +280,7 @@ public class Precision {
      * @since 2.2
      */
     public static boolean equalsIncludingNaN(double x, double y) {
-        return (Double.isNaN(x) && Double.isNaN(y)) || equals(x, y, 1);
+        return (x != x || y != y) ? !(x != x ^ y != y) : equals(x, y, 1);
     }
 
     /**
@@ -403,7 +403,7 @@ public class Precision {
      * @since 2.2
      */
     public static boolean equalsIncludingNaN(double x, double y, int maxUlps) {
-        return (Double.isNaN(x) && Double.isNaN(y)) || equals(x, y, maxUlps);
+        return (x != x || y != y) ? !(x != x ^ y != y) : equals(x, y, maxUlps);
     }
 
     /**