MATH-849: Gamma.gamma(double) returns NaN if called on negative integer.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1413802 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastien Brisard 2012-11-26 19:45:52 +00:00
parent f348a29e5f
commit fec7740958
2 changed files with 11 additions and 1 deletions

View File

@ -706,7 +706,9 @@ public class Gamma {
*/
public static double gamma(final double x) {
// TODO Check whether x is a negative integer
if ((x == FastMath.rint(x)) && (x <= 0.0)) {
return Double.NaN;
}
final double ret;
final double absX = FastMath.abs(x);

View File

@ -954,6 +954,14 @@ public class GammaTest {
}
}
@Test
public void testGammaNegativeInteger() {
for (int i = -100; i <= 0; i++) {
Assert.assertTrue(Integer.toString(i), Double.isNaN(Gamma.gamma(i)));
}
}
/**
* Reference data for the {@link Gamma#logGammaSum(double, double)}
* function. This data was generated with the following