MATH-904.
Fixed wrong assumption in "pow" method. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1413916 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4673043763
commit
6844aba987
|
@ -52,6 +52,9 @@ If the output is not quite correct, check for invisible trailing spaces!
|
|||
<body>
|
||||
<release version="3.1" date="TBD" description="
|
||||
">
|
||||
<action dev="erans" type="fix" issue="MATH-904" due-to="Jeff Hain">
|
||||
Fixed "pow" method in class "FastMath".
|
||||
</action>
|
||||
<action dev="erans" type="update" issue="MATH-902" due-to="Bruce A. Johnson">
|
||||
Created a "maximum number of iterations" stopping criterion in the
|
||||
convergence checkers (package "o.a.c.m.optimization") that allows the
|
||||
|
|
|
@ -309,6 +309,8 @@ public class FastMath {
|
|||
|
||||
/** 2^52 - double numbers this large must be integral (no fraction) or NaN or Infinite */
|
||||
private static final double TWO_POWER_52 = 4503599627370496.0;
|
||||
/** 2^53 - double numbers this large must be even. */
|
||||
private static final double TWO_POWER_53 = 2 * TWO_POWER_52;
|
||||
|
||||
/** Constant: {@value}. */
|
||||
private static final double F_1_3 = 1d / 3d;
|
||||
|
@ -1537,7 +1539,7 @@ public class FastMath {
|
|||
/* Handle special case x<0 */
|
||||
if (x < 0) {
|
||||
// y is an even integer in this case
|
||||
if (y >= TWO_POWER_52 || y <= -TWO_POWER_52) {
|
||||
if (y >= TWO_POWER_53 || y <= -TWO_POWER_53) {
|
||||
return pow(-x, y);
|
||||
}
|
||||
|
||||
|
|
|
@ -157,6 +157,16 @@ public class FastMathTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMath904() {
|
||||
final double x = -1;
|
||||
final double y = (5 + 1e-15) * 1e15;
|
||||
Assert.assertEquals(Math.pow(x, y),
|
||||
FastMath.pow(x, y), 0);
|
||||
Assert.assertEquals(Math.pow(x, -y),
|
||||
FastMath.pow(x, -y), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMath905LargePositive() {
|
||||
final double start = StrictMath.log(Double.MAX_VALUE);
|
||||
|
|
Loading…
Reference in New Issue