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

Result of multiplying and equals for complex numbers is wrong

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.2
    • None
    • None
    • None

    Description

      Hi.

      The bug relates on complex numbers.
      The methods "multiply" and "equals" of the class Complex are involved.

      mathematic background: (0,i) * (-1,0i) = (0,-i).

      little java program + output that shows the bug:
      -----------------------------------------------------------------------

      import org.apache.commons.math.complex.*;
      public class TestProg {
              public static void main(String[] args) {
      
                      ComplexFormat f = new ComplexFormat();
                      Complex c1 = new Complex(0,1);
                      Complex c2 = new Complex(-1,0);
      
                      Complex res = c1.multiply(c2);
                      Complex comp = new Complex(0,-1);
      
                      System.out.println("res:  "+f.format(res));
                      System.out.println("comp: "+f.format(comp));
      
                      System.out.println("res=comp: "+res.equals(comp));
              }
      }
      

      -----------------------------------------------------------------------

      res: -0 - 1i
      comp: 0 - 1i
      res=comp: false

      -----------------------------------------------------------------------

      I think the "equals" should return "true".
      The problem could either be the "multiply" method that gives (-0,-1i) instead of (0,-1i),
      or if you think thats right, the equals method has to be modified.

      Good Luck
      Dieter

      Attachments

        Activity

          People

            Unassigned Unassigned
            news.dieter Dieter Roth
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: