Uploaded image for project: 'Commons Numbers'
  1. Commons Numbers
  2. NUMBERS-48

Unreachable statements in Complex.abs()

    XMLWordPrintableJSON

Details

    • Patch

    Description

      This return statement in Complex.abs() is unreachable:

      if (FastMath.abs(real) < FastMath.abs(imaginary)) {
        if (imaginary == 0.0) {
          return FastMath.abs(real);
        }
      

      If imaginary == 0, then there's no way that the preceding condition would be true. There are two similar inner 'if' statements that were accidentally switched. Returned values are still correct, but performance suffers.

      The attached patch switches these back. Note that we're still protected from dividing by zero.

      Attachments

        1. complex_abs.patch
          1.0 kB
          David Nickerson

        Activity

          People

            Unassigned Unassigned
            David Nickerson David Nickerson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: