MATH-1269: fixed FastMath.exp returning NaN for non-NaN arguments

This commit is contained in:
Otmar Ertl 2015-11-05 20:37:27 +01:00
parent 793e9df043
commit a94ff90ab6
3 changed files with 19 additions and 0 deletions

View File

@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
</release>
<release version="4.0" date="XXXX-XX-XX" description="">
<action dev="oertl" type="fix" issue="MATH-1269"> <!-- backported to 3.6 -->
Fixed FastMath.exp that potentially returned NaN for non-NaN argument.
</action>
<action dev="luc" type="add"> <!-- backported to 3.6 -->
Added a nth order Brent solver for general real fields, replacing the former
solver that was restricted to Dfp fields only.

View File

@ -968,6 +968,13 @@ public class FastMath {
much larger than the others. If there are extra bits specified from the
pow() function, use them. */
final double tempC = tempB + tempA;
// If tempC is positive infinite, the evaluation below could result in NaN,
// because z could be negative at the same time.
if (tempC == Double.POSITIVE_INFINITY) {
return Double.POSITIVE_INFINITY;
}
final double result;
if (extra != 0.0) {
result = tempC*extra*z + tempC*extra + tempC*z + tempB + tempA;

View File

@ -217,6 +217,15 @@ public class FastMathTest {
}
Assert.assertEquals(0, maxErr, 3);
}
@Test
public void testMath1269() {
final double arg = 709.8125;
final double vM = Math.exp(arg);
final double vFM = FastMath.exp(arg);
Assert.assertTrue("exp(" + arg + ") is " + vFM + " instead of " + vM,
Precision.equalsIncludingNaN(vM, vFM));
}
@Test
public void testHyperbolicInverses() {