commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luc Maisonobe (JIRA)" <>
Subject [jira] [Created] (MATH-1223) Wrong splitting of huge double numbers
Date Thu, 07 May 2015 13:21:00 GMT
Luc Maisonobe created MATH-1223:

             Summary: Wrong splitting of huge double numbers
                 Key: MATH-1223
             Project: Commons Math
          Issue Type: Bug
    Affects Versions: 3.5
            Reporter: Luc Maisonobe
            Priority: Minor
             Fix For: 4.0

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

This message was sent by Atlassian JIRA

View raw message