You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Richard Lyon (JIRA)" <ji...@apache.org> on 2007/05/08 05:31:15 UTC

[jira] Created: (MATH-164) Complex - Issue with non-compliance to C99!

Complex - Issue with non-compliance to C99!
-------------------------------------------

                 Key: MATH-164
                 URL: https://issues.apache.org/jira/browse/MATH-164
             Project: Commons Math
          Issue Type: Wish
    Affects Versions: 1.1
            Reporter: Richard Lyon
            Priority: Minor


Complex z1, z2, z3;
        
// assign values to the two complex numbers
z1 = new Complex(1.0, 0.0);
z2 = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
       
// multiply the two complex numbers
z3 = z1.multiply(z2);

The result is that both the real and imaginary part of z3 are NaN. Isn't it somewhat desirable that both parts of the complex should be Infinity?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Commented: (MATH-164) Complex - Issue with non-compliance to C99!

Posted by "Richard Lyon (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-164?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12494424 ] 

Richard Lyon commented on MATH-164:
-----------------------------------

I don't believe full compliance with C99 is required or desirable. For instance the classification of whether a complex is a NaN or Infinite. If a complex number has a component which is a NaN, why would you want to classify the complex as anything but NaN? Isn't this going to effect just about every function which takes a complex operand?

However to maintain some consistency with the way java handles doubles it is necessary to comply with many parts of C99. A typical example is the case I have reported.

I have only been testing using the sun jdk and jre. What about other implementations?

> Complex - Issue with non-compliance to C99!
> -------------------------------------------
>
>                 Key: MATH-164
>                 URL: https://issues.apache.org/jira/browse/MATH-164
>             Project: Commons Math
>          Issue Type: Wish
>    Affects Versions: 1.1
>            Reporter: Richard Lyon
>            Priority: Minor
>
> Complex z1, z2, z3;
>         
> // assign values to the two complex numbers
> z1 = new Complex(1.0, 0.0);
> z2 = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
>        
> // multiply the two complex numbers
> z3 = z1.multiply(z2);
> The result is that both the real and imaginary part of z3 are NaN. Isn't it somewhat desirable that both parts of the complex should be Infinity?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Commented: (MATH-164) Complex - Issue with non-compliance to C99!

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-164?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12494375 ] 

Luc Maisonobe commented on MATH-164:
------------------------------------

I confirm the issue. Currently, the multiplication operator is implemented using a single check for NaN and using the simple rules on real and imaginary parts if the check succeeds.

A quick check shows that there are several other related problems. For example, the isInfinite method checks for isNaN first and checks for infinite parts only afterwards. However, C99 explicitely states that a complex is considered to be an infinity as soon as one part is infinity, even if the other one is NaN.

So it appears that the handling of special values like NaN and infinity in the Complex class is not compliant with C99 at several places. Solving this needs some forethought.

Thanks for reporting it.

> Complex - Issue with non-compliance to C99!
> -------------------------------------------
>
>                 Key: MATH-164
>                 URL: https://issues.apache.org/jira/browse/MATH-164
>             Project: Commons Math
>          Issue Type: Wish
>    Affects Versions: 1.1
>            Reporter: Richard Lyon
>            Priority: Minor
>
> Complex z1, z2, z3;
>         
> // assign values to the two complex numbers
> z1 = new Complex(1.0, 0.0);
> z2 = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
>        
> // multiply the two complex numbers
> z3 = z1.multiply(z2);
> The result is that both the real and imaginary part of z3 are NaN. Isn't it somewhat desirable that both parts of the complex should be Infinity?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Commented: (MATH-164) Complex - Issue with non-compliance to C99!

Posted by "Richard Lyon (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-164?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12494178 ] 

Richard Lyon commented on MATH-164:
-----------------------------------

The behaviour is not consistant with how doubles are handled. For example:

double a, b ,c;

a = 1.0;
b = Double.POSITIVE_INFINITY;

c = a * b;

c always has a value of  Infinity. So why should the Complex class handle it differently? This is addressed in the C99 spec and various associated discussion papers.



> Complex - Issue with non-compliance to C99!
> -------------------------------------------
>
>                 Key: MATH-164
>                 URL: https://issues.apache.org/jira/browse/MATH-164
>             Project: Commons Math
>          Issue Type: Wish
>    Affects Versions: 1.1
>            Reporter: Richard Lyon
>            Priority: Minor
>
> Complex z1, z2, z3;
>         
> // assign values to the two complex numbers
> z1 = new Complex(1.0, 0.0);
> z2 = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
>        
> // multiply the two complex numbers
> z3 = z1.multiply(z2);
> The result is that both the real and imaginary part of z3 are NaN. Isn't it somewhat desirable that both parts of the complex should be Infinity?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Commented: (MATH-164) Complex - Issue with non-compliance to C99!

Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-164?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12494617 ] 

Phil Steitz commented on MATH-164:
----------------------------------

I agree with Richard here and will add a little historical context.  Initially, we planned to fully implement C99x.   In addition to the fact that the spec itself was neither final nor freely available when [math] 1.1 was released (I had to get special permission to even quote from it in the javadoc), it is a C spec and very difficult if not impossible to fully implement and document in Java with decent performance.   We opted to take the approach of trying to stay as close as possible to the spec while not abusing Java semantics or killing performance, documenting carefully what we did for each operation.  The javadoc for multiply is a good example.  The example above could be added as an additional example illustrating what the formula yields.

We are open to suggestions for improvement.  Probably best to discuss on commons-dev.

> Complex - Issue with non-compliance to C99!
> -------------------------------------------
>
>                 Key: MATH-164
>                 URL: https://issues.apache.org/jira/browse/MATH-164
>             Project: Commons Math
>          Issue Type: Wish
>    Affects Versions: 1.1
>            Reporter: Richard Lyon
>            Priority: Minor
>
> Complex z1, z2, z3;
>         
> // assign values to the two complex numbers
> z1 = new Complex(1.0, 0.0);
> z2 = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
>        
> // multiply the two complex numbers
> z3 = z1.multiply(z2);
> The result is that both the real and imaginary part of z3 are NaN. Isn't it somewhat desirable that both parts of the complex should be Infinity?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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