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/09/07 13:36:05 UTC

Re: 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

Hi Eric.

On Thu,  7 Sep 2017 13:18:46 +0000 (UTC), ericbarnhill@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 <er...@apache.org>
> Authored: Thu Sep 7 15:21:28 2017 +0200
> Committer: Eric Barnhill <er...@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-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org