You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/08/18 17:30:56 UTC

[commons-math] branch master updated: Sonar fix: Replace x != x with Double.isNaN

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git


The following commit(s) were added to refs/heads/master by this push:
     new f6fe96b  Sonar fix: Replace x != x with Double.isNaN
f6fe96b is described below

commit f6fe96b23fededca66c998e41c28fc2a6d73d6ee
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Aug 18 18:30:53 2021 +0100

    Sonar fix: Replace x != x with Double.isNaN
---
 .../src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java     | 2 +-
 .../org/apache/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 41f15c9..02f7df8 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<Dfp> {
 
         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 69cc11b..e9ec154 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,";