Repository: commons-numbers Updated Branches: refs/heads/hypot-change [created] b2df9248d
NUMBERS-27: Replaced hand-coded hypot with Java.lang.Math hypot Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/b2df9248 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/b2df9248 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/b2df9248 Branch: refs/heads/hypot-change Commit: b2df9248d8e2e36732a535d92b0ff629e47d1694 Parents: 1e4947b Author: Eric Barnhill <ericbarnh...@apache.org> Authored: Wed Apr 26 00:39:28 2017 +0200 Committer: Eric Barnhill <ericbarnh...@apache.org> Committed: Wed Apr 26 00:39:28 2017 +0200 ---------------------------------------------------------------------- .../apache/commons/numbers/complex/Complex.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b2df9248/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 4e9022e..cfd7a39 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 @@ -109,18 +109,17 @@ public class Complex implements Serializable { if (isInfinite()) { return Double.POSITIVE_INFINITY; } - if (Math.abs(real) < Math.abs(imaginary)) { - if (imaginary == 0.0) { - return Math.abs(real); + if (Math.abs(getReal()) < Math.abs(getImaginary())) { + if (getImaginary() == 0.0) { + return Math.abs(getReal()); } - double q = real / imaginary; - return Math.abs(imaginary) * Math.sqrt(1 + q * q); + double q = getReal() / getImaginary(); + return Math.abs(getImaginary()) * Math.sqrt(1 + q * q); } else { - if (real == 0.0) { - return Math.abs(imaginary); + if (getReal() == 0.0) { + return Math.abs(getImaginary()); } - double q = imaginary / real; - return Math.abs(real) * Math.sqrt(1 + q * q); + return Math.hypot(getReal(), getImaginary()); } }