commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1413802 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/special/Gamma.java test/java/org/apache/commons/math3/special/GammaTest.java
Date Mon, 26 Nov 2012 19:45:53 GMT
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



Mime
View raw message