You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/12/05 00:45:55 UTC

[commons-numbers] 04/04: Preserve even function in cosh

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit 8963bd191ca80af6b1ba3f94998d5be0d64e43ac
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Thu Dec 5 00:44:27 2019 +0000

    Preserve even function in cosh
---
 .../java/org/apache/commons/numbers/complex/Complex.java   | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

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 490380b..e5b9ca8 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
@@ -1241,6 +1241,12 @@ public final class Complex implements Serializable  {
                 return constructor.create(Math.cosh(real) * Math.cos(imaginary),
                                           Math.sinh(real) * Math.sin(imaginary));
             }
+            // ISO C99: Preserve the even function
+            // f(z) = f(-z)
+            if (negative(real)) {
+                real = -real;
+                imaginary = -imaginary;
+            }
             // Special case for real == 0
             final double im = real == 0 ? Math.copySign(0, imaginary) : Double.NaN;
             return constructor.create(Double.NaN, im);
@@ -1253,6 +1259,12 @@ public final class Complex implements Serializable  {
                     return constructor.create(Double.POSITIVE_INFINITY, im);
                 }
                 // inf * cis(y)
+                // ISO C99: Preserve the even function
+                // f(z) = f(-z)
+                if (real < 0) {
+                    real = -real;
+                    imaginary = -imaginary;
+                }
                 final double re = real * Math.cos(imaginary);
                 final double im = real * Math.sin(imaginary);
                 return constructor.create(re, im);
@@ -1262,7 +1274,7 @@ public final class Complex implements Serializable  {
         }
         // real is NaN
         if (imaginary == 0) {
-            return constructor.create(Double.NaN, Math.copySign(0, imaginary));
+            return constructor.create(Double.NaN, imaginary);
         }
         // optionally raises the ‘‘invalid’’ floating-point exception, for nonzero y.
         return NAN;


Re: [commons-numbers] 04/04: Preserve even function in cosh

Posted by Alex Herbert <al...@gmail.com>.

> On 5 Dec 2019, at 01:39, Gilles Sadowski <gi...@gmail.com> wrote:
> 
> Test failure here:
> ---CUT---
> ERROR] Failures:
> [ERROR]   CStandardTest.testCosh:692->assertComplex:275 Operation
> failed (z=(-Infinity,0.5)). Expected: (-Infinity,-Infinity) but was:
> (Infinity,-Infinity)
> —CUT—
> 

Sorry. I thought I had fixed it. 

I have pushed another fix that should correct the odd/even function properties of all the complex functions for normal use cases. The edge cases need to be addressed separately.

Alex


> Gilles
> 
> 2019-12-05 1:45 UTC+01:00, aherbert@apache.org <ah...@apache.org>:
>> This is an automated email from the ASF dual-hosted git repository.
>> 
>> aherbert pushed a commit to branch master
>> in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
>> 
>> commit 8963bd191ca80af6b1ba3f94998d5be0d64e43ac
>> Author: Alex Herbert <ah...@apache.org>
>> AuthorDate: Thu Dec 5 00:44:27 2019 +0000
>> 
>>    Preserve even function in cosh
>> ---
>> .../java/org/apache/commons/numbers/complex/Complex.java   | 14
>> +++++++++++++-
>> 1 file changed, 13 insertions(+), 1 deletion(-)
>> 
>> 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 490380b..e5b9ca8 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
>> @@ -1241,6 +1241,12 @@ public final class Complex implements Serializable
>> {
>>                 return constructor.create(Math.cosh(real) *
>> Math.cos(imaginary),
>>                                           Math.sinh(real) *
>> Math.sin(imaginary));
>>             }
>> +            // ISO C99: Preserve the even function
>> +            // f(z) = f(-z)
>> +            if (negative(real)) {
>> +                real = -real;
>> +                imaginary = -imaginary;
>> +            }
>>             // Special case for real == 0
>>             final double im = real == 0 ? Math.copySign(0, imaginary) :
>> Double.NaN;
>>             return constructor.create(Double.NaN, im);
>> @@ -1253,6 +1259,12 @@ public final class Complex implements Serializable
>> {
>>                     return constructor.create(Double.POSITIVE_INFINITY,
>> im);
>>                 }
>>                 // inf * cis(y)
>> +                // ISO C99: Preserve the even function
>> +                // f(z) = f(-z)
>> +                if (real < 0) {
>> +                    real = -real;
>> +                    imaginary = -imaginary;
>> +                }
>>                 final double re = real * Math.cos(imaginary);
>>                 final double im = real * Math.sin(imaginary);
>>                 return constructor.create(re, im);
>> @@ -1262,7 +1274,7 @@ public final class Complex implements Serializable  {
>>         }
>>         // real is NaN
>>         if (imaginary == 0) {
>> -            return constructor.create(Double.NaN, Math.copySign(0,
>> imaginary));
>> +            return constructor.create(Double.NaN, imaginary);
>>         }
>>         // optionally raises the ‘‘invalid’’ floating-point exception, for
>> nonzero y.
>>         return NAN;
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 


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


Re: [commons-numbers] 04/04: Preserve even function in cosh

Posted by Gilles Sadowski <gi...@gmail.com>.
Test failure here:
---CUT---
ERROR] Failures:
[ERROR]   CStandardTest.testCosh:692->assertComplex:275 Operation
failed (z=(-Infinity,0.5)). Expected: (-Infinity,-Infinity) but was:
(Infinity,-Infinity)
---CUT---

Gilles

2019-12-05 1:45 UTC+01:00, aherbert@apache.org <ah...@apache.org>:
> This is an automated email from the ASF dual-hosted git repository.
>
> aherbert pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
>
> commit 8963bd191ca80af6b1ba3f94998d5be0d64e43ac
> Author: Alex Herbert <ah...@apache.org>
> AuthorDate: Thu Dec 5 00:44:27 2019 +0000
>
>     Preserve even function in cosh
> ---
>  .../java/org/apache/commons/numbers/complex/Complex.java   | 14
> +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
>
> 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 490380b..e5b9ca8 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
> @@ -1241,6 +1241,12 @@ public final class Complex implements Serializable
> {
>                  return constructor.create(Math.cosh(real) *
> Math.cos(imaginary),
>                                            Math.sinh(real) *
> Math.sin(imaginary));
>              }
> +            // ISO C99: Preserve the even function
> +            // f(z) = f(-z)
> +            if (negative(real)) {
> +                real = -real;
> +                imaginary = -imaginary;
> +            }
>              // Special case for real == 0
>              final double im = real == 0 ? Math.copySign(0, imaginary) :
> Double.NaN;
>              return constructor.create(Double.NaN, im);
> @@ -1253,6 +1259,12 @@ public final class Complex implements Serializable
> {
>                      return constructor.create(Double.POSITIVE_INFINITY,
> im);
>                  }
>                  // inf * cis(y)
> +                // ISO C99: Preserve the even function
> +                // f(z) = f(-z)
> +                if (real < 0) {
> +                    real = -real;
> +                    imaginary = -imaginary;
> +                }
>                  final double re = real * Math.cos(imaginary);
>                  final double im = real * Math.sin(imaginary);
>                  return constructor.create(re, im);
> @@ -1262,7 +1274,7 @@ public final class Complex implements Serializable  {
>          }
>          // real is NaN
>          if (imaginary == 0) {
> -            return constructor.create(Double.NaN, Math.copySign(0,
> imaginary));
> +            return constructor.create(Double.NaN, imaginary);
>          }
>          // optionally raises the ‘‘invalid’’ floating-point exception, for
> nonzero y.
>          return NAN;
>
>

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