Fixed infinite loop in FastMath.pow(double, long) with Long.MIN_VALUE.

JIRA: MATH-1272
This commit is contained in:
Luc Maisonobe 2015-09-10 09:49:05 +02:00
parent 941b13f8ed
commit 26e878ab3a
3 changed files with 10 additions and 2 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="luc" type="fix" issue="MATH-1272" due-to="Qualtagh">
Fixed infinite loop in FastMath.pow(double, long) with Long.MIN_VALUE.
</action>
<action dev="luc" type="fix" issue="MATH-1266"> <!-- backported to 3.6 -->
Fixed split/side inconsistencies in BSP trees.
</action>

View File

@ -1711,7 +1711,7 @@ public class FastMath {
}
/** Computes this^e.
* @param e exponent (beware, here it MUST be > 0)
* @param e exponent (beware, here it MUST be > 0; the only exclusion is Long.MIN_VALUE)
* @return d^e, split in high and low bits
* @since 4.0
*/
@ -1723,7 +1723,7 @@ public class FastMath {
// d^(2p)
Split d2p = new Split(full, high, low);
for (long p = e; p != 0; p >>= 1) {
for (long p = e; p != 0; p >>>= 1) {
if ((p & 0x1) != 0) {
// accurate multiplication result = result * d^(2p) using Veltkamp TwoProduct algorithm

View File

@ -1232,6 +1232,11 @@ public class FastMathTest {
Assert.assertTrue(Double.isInfinite(FastMath.pow(FastMath.scalb(1.0, 500), 4)));
}
@Test(timeout=5000L) // This test must finish in finite time.
public void testIntPowLongMinValue() {
Assert.assertEquals(1.0, FastMath.pow(1.0, Long.MIN_VALUE), -1.0);
}
@Test
public void testIncrementExactInt() {
int[] specialValues = new int[] {