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.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.1, 1.2, 2.0
    • Fix Version/s: 2.1
    • Labels:
      None
    • Environment:

      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

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

              Dates

              • Created:
                Updated:
                Resolved: