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

Wrong splitting of huge double numbers

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.5
    • 4.0, 3.6
    • None
    • None

    Description

      In both MathArrays and FastMath, some computations on double are performed by firt splitting double numbers in two numbers with about 26 bits.

      This splitting fails when the numbers are huge, even if they are still representable and not infinite (the limit is about 1.0e300, eight orders of magnitude below infinity).

      This can be seen by computing for example

      FastMath.pow(FastMath.scalb(1.0, 500), 4);
      

      The result is NaN whereas it should be +infinity.

      or by modifying test MathArraysTest.testLinearCombination1 and scaling down first array elements by FastMath.scalb(a[i], -971) and scaling up the second array elements by FastMath.scalb(b[i], +971), which should not change the results. Here the result is a loss of precision because a safety check in MathArrays.linearCombination falls back to naive implementation if the high accuracy algorithm fails.

      The reason for the wrong splitting is an overflow when computing

              final int splitFactor = 0x8000001;
              final double cd       = splitFactor * d; // <--- overflow
      
      
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            luc Luc Maisonobe
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: