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

Method 'divide' in class 'Complex' uses a false formula for a special case resulting in erroneous division by zero.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1, 1.2, 2.0
    • 2.1
    • None
    • None
    • all

    Description

      The formula that 'divide' wants to implement is

      ( a + bi ) / ( c + di ) = ( ac + bd + ( bc - ad ) i ) / ( c^2 + d^2 )

      as correctly written in the description.

      When c == 0.0 this leads to the special case

      ( a + bi ) / di = ( b / d ) - ( a / d ) i

      But the corresponding code is:

      if (c == 0.0) {
      return createComplex(imaginary/d, -real/c);
      }

      The bug is the last division -real/c, which should obviously be -real/d.

      Attachments

        Activity

          People

            Unassigned Unassigned
            bowman2001 Joerg Huber
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: