You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gilles <gi...@harfang.homelinux.org> on 2017/04/26 00:18:19 UTC

Re: commons-numbers git commit: NUMBERS-27: Replaced hand-coded hypot with Java.lang.Math hypot

Hi Eric.

In the code below, any reason why you use the "accessor" method rather
than refer directly to the instance fields?

Regards,
Gilles

On Tue, 25 Apr 2017 22:40:29 +0000 (UTC), ericbarnhill@apache.org 
wrote:
> 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 <er...@apache.org>
> Authored: Wed Apr 26 00:39:28 2017 +0200
> Committer: Eric Barnhill <er...@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());
>          }
>      }


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