From f6fe96b23fededca66c998e41c28fc2a6d73d6ee Mon Sep 17 00:00:00 2001 From: Alex Herbert Date: Wed, 18 Aug 2021 18:30:53 +0100 Subject: [PATCH] Sonar fix: Replace x != x with Double.isNaN --- .../main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java | 2 +- .../commons/math4/legacy/core/jdkmath/AccurateMathCalc.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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,";