MATH-1130

Shortcut (in case one of the arguments is NaN). Thanks to Venkatesha Murthy.


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1605777 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2014-06-26 13:08:55 +00:00
parent 75d4db00e1
commit 08e918330e
1 changed files with 4 additions and 4 deletions

View File

@ -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);
}
/**