commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Axel Kramer (JIRA)" <j...@apache.org>
Subject [jira] Commented: (MATH-402) Complex.ZERO.pow(Complex.ONE) gives NaN in unit tests
Date Sat, 07 Aug 2010 11:26:16 GMT

    [ https://issues.apache.org/jira/browse/MATH-402?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12896247#action_12896247
] 

Axel Kramer commented on MATH-402:
----------------------------------

Sorry for my stupid suggestion in the first post.

It should be something like this:
{code:java}
	public Complex pow(Complex x) {
		if (x == null) {
			throw new NullPointerException();
		}
		if (x.real == 0.0 && x.imaginary == 0.0) {
			if (real == 0.0 && imaginary == 0.0) {
				// 0^0 => NaN
				return Complex.NaN;
			}
			// THIS^0 => 1 for THIS<>0
			return Complex.ONE;
		}
		if (real == 0.0 && imaginary == 0.0) {
			// 0^x => 0 for x<>0
			return Complex.ZERO;
		}
		return this.log().multiply(x).exp();
	}
{code}

> Complex.ZERO.pow(Complex.ONE) gives NaN in unit tests
> -----------------------------------------------------
>
>                 Key: MATH-402
>                 URL: https://issues.apache.org/jira/browse/MATH-402
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>         Environment: Issue 15 http://code.google.com/p/symja/issues/detail?id=15
>            Reporter: Axel Kramer
>
> Why does this unit test in ComplexTest.java gives NaN?
> I expected to get Complex.ZERO as the result?
> {code:java} 
>    public void testPowZero() {
>        TestUtils.assertSame(Complex.NaN,
>                Complex.ZERO.pow(Complex.ONE));
> ...
>    }
> {code} 
> I would suggest something like this for the Complex#pow() method:
> {code:java} 
>     public Complex pow(Complex x) {
>         if (x == null) {
>             throw new NullPointerException();
>         }
>         if (x.imaginary == 0.0) {
>           if (real == 0.0 && imaginary == 0.0) {
>             if (x.real == 0.0){      	
>             	return Complex.ZERO;
>             }
>           }
>           if (x.real == 1.0) {
>           	return this;
>           }
>         }
>         return this.log().multiply(x).exp();
>     }
> {code} 
>  

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


Mime
View raw message