[MATH-1283] Fixed Gamma#gamma function for values smaller than -20. Thanks to Jean Noel Delavalade
This commit is contained in:
parent
0dd621687d
commit
40f35da565
|
@ -51,6 +51,9 @@ If the output is not quite correct, check for invisible trailing spaces!
|
|||
</properties>
|
||||
<body>
|
||||
<release version="3.6" date="XXXX-XX-XX" description="">
|
||||
<action dev="tn" type="fix" issue="MATH-1283" due-to="Jean Noel Delavalade">
|
||||
Fixed "Gamma#gamma(double)" for negative values smaller than -20.
|
||||
</action>
|
||||
<action dev="tn" type="fix" issue="MATH-1237" due-to="Ken Williams">
|
||||
Fixed javadoc of methods {floorDiv,floorMod} in class "FastMath".
|
||||
</action>
|
||||
|
|
|
@ -695,7 +695,7 @@ public class Gamma {
|
|||
}
|
||||
} else {
|
||||
final double y = absX + LANCZOS_G + 0.5;
|
||||
final double gammaAbs = SQRT_TWO_PI / x *
|
||||
final double gammaAbs = SQRT_TWO_PI / absX *
|
||||
FastMath.pow(y, absX + 0.5) *
|
||||
FastMath.exp(-y) * lanczos(absX);
|
||||
if (x > 0.0) {
|
||||
|
|
|
@ -974,6 +974,21 @@ public class GammaTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGammaNegativeDouble() {
|
||||
// check that the gamma function properly switches sign
|
||||
// see: https://en.wikipedia.org/wiki/Gamma_function
|
||||
|
||||
double previousGamma = Gamma.gamma(-18.5);
|
||||
for (double x = -19.5; x > -25; x -= 1.0) {
|
||||
double gamma = Gamma.gamma(x);
|
||||
Assert.assertEquals( (int) FastMath.signum(previousGamma),
|
||||
- (int) FastMath.signum(gamma));
|
||||
|
||||
previousGamma = gamma;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkRelativeError(String msg, double expected, double actual,
|
||||
double tolerance) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue