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

Method reciprocal() in Complex for complex numbers with parts very close to 0.0

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.0-beta1
    • complex
    • None

    Description

      I have been redirected here from the issue repository of Apache Commons Math, as the Complex class will likely be deprecated in favour of its equivalent in "Commons Numbers".

      In class Complex method reciprocal() returns INF only if the real and imaginary parts are exactly equal to 0.0. In the cases when real and imaginary parts are double numbers very close to 0.0, it does not hold. For example, if we run this code

      Complex complex0 = new Complex((-2.44242319E-315));
      Complex complex1 = complex0.reciprocal();
      

      the value of complex1.getReal() will be -Infinity and the value of complex1.getImaginary() will be NaN, instead of complex1 being equal to INF.

      The suggested solutions after the discussion are either checking the equality to ZERO with some tolerance or to detect if one of the real or imaginary parts is going to be infinite or NaN and then return the proper result.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              gjahanagirova Gunel Jahangirova
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: