Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-402

Complex.ZERO.pow(Complex.ONE) gives NaN in unit tests

    XMLWordPrintableJSON

Details

    Description

      Why does this unit test in ComplexTest.java gives NaN?
      I expected to get Complex.ZERO as the result?

       
         public void testPowZero() {
             TestUtils.assertSame(Complex.NaN,
                     Complex.ZERO.pow(Complex.ONE));
      ...
         }
      

      I would suggest something like this for the Complex#pow() method:

       
          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();
          }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            axelclk Axel Kramer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: