Hi Eric.

On Thu, 7 Sep 2017 13:18:46 +0000 (UTC), ericbarnh...@apache.org wrote:
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 <ericbarnh...@apache.org>
Authored: Thu Sep 7 15:21:28 2017 +0200
Committer: Eric Barnhill <ericbarnh...@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;

Constant should be "final".

             double scale = 1. / (real * q + imaginary);

"final"

-            return new Complex(scale * q, -scale);
+            double scaleQ;

Wouldn't it be better to assign 0 as default?
Seems to reduce code.

+            if (q == 0 | scale == 0) {

Typo? Should be "||".

+                scaleQ = 0;
+            } else {
+                scaleQ = scale * q;
+            }
+            return new Complex(scaleQ, -scale);
         } else {
             double q = imaginary / real;

"final"

             double scale = 1. / (imaginary * q + real);

"final"

-            return new Complex(scale, -scale * q);
+            double scaleQ;
+            if (q == 0 | scale == 0) {

"||"

+                scaleQ = 0;
+            } else {
+                scaleQ = scale * q;
+            }
+            return new Complex(scale, -scaleQ);
         }
     }

Regards,
Gilles


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to