commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ericbarnh...@apache.org
Subject commons-numbers git commit: NUMBERS-22: if block added to ensure that reciprocal of very small real numbers return an imaginary component of 0 rather than NaN
Date Thu, 07 Sep 2017 13:18:46 GMT
Repository: commons-numbers
Updated Branches:
  refs/heads/complex-dev ec3bb9ed9 -> f0d1b9cdc


NUMBERS-22: if block added to ensure that reciprocal of very small real numbers return an
imaginary component of 0 rather than NaN


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/f0d1b9cd
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/f0d1b9cd
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/f0d1b9cd

Branch: refs/heads/complex-dev
Commit: f0d1b9cdc279c5438a799d62b74effb7ece4958b
Parents: ec3bb9e
Author: Eric Barnhill <ericbarnhill@apache.org>
Authored: Thu Sep 7 15:21:28 2017 +0200
Committer: Eric Barnhill <ericbarnhill@apache.org>
Committed: Thu Sep 7 15:21:28 2017 +0200

----------------------------------------------------------------------
 .../org/apache/commons/numbers/complex/Complex.java | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/f0d1b9cd/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index 7fcbbf4..d396619 100644
--- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
@@ -355,11 +355,23 @@ in the
         if (Math.abs(real) < Math.abs(imaginary)) {
             double q = real / imaginary;
             double scale = 1. / (real * q + imaginary);
-            return new Complex(scale * q, -scale);
+            double scaleQ;
+            if (q == 0 | scale == 0) {
+                scaleQ = 0;
+            } else {
+                scaleQ = scale * q;
+            }
+            return new Complex(scaleQ, -scale);
         } else {
             double q = imaginary / real;
             double scale = 1. / (imaginary * q + real);
-            return new Complex(scale, -scale * q);
+            double scaleQ;
+            if (q == 0 | scale == 0) {
+                scaleQ = 0;
+            } else {
+                scaleQ = scale * q;
+            }
+            return new Complex(scale, -scaleQ);
         }
     }
 


Mime
View raw message