Author: celestin
Date: Mon Nov 26 19:45:52 2012
New Revision: 1413802

URL: http://svn.apache.org/viewvc?rev=1413802&view=rev
Log:
MATH-849: Gamma.gamma(double) returns NaN if called on negative integer.

Modified:
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/GammaTest.java

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java?rev=1413802&r1=1413801&r2=1413802&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Gamma.java
 Mon Nov 26 19:45:52 2012
@@ -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);

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/GammaTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/GammaTest.java?rev=1413802&r1=1413801&r2=1413802&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/GammaTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/GammaTest.java
 Mon Nov 26 19:45:52 2012
@@ -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


Reply via email to