diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java index 41f15c911..02f7df81e 100644 --- a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java @@ -288,7 +288,7 @@ public class Dfp implements RealFieldElement { if (exponent == 1024) { // infinity or NAN - if (x != x) { + if (Double.isNaN(x)) { sign = (byte) 1; nans = QNAN; } else if (x < 0) { diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java index 69cc11b72..e9ec154ff 100644 --- a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java @@ -636,7 +636,7 @@ final class AccurateMathCalc { * @return formatted number */ static String format(double d) { - if (d != d) { + if (Double.isNaN(d)) { return "Double.NaN,"; } else { return ((d >= 0) ? "+" : "") + Double.toString(d) + "d,";