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

Result of multiplying and equals for complex numbers is wrong

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      OS: Debian lenny
      IDE: Eclipse; Version: 3.4.0; Build id: I20080617-2000
      java.runtime.version=1.6.0_04-b12
      java.vendor.url=http://java.sun.com/

      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

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

              Dates

              • Created:
                Updated:
                Resolved: