Repository: commons-numbers
Updated Branches:
  refs/heads/master 1aa1ddcd5 -> d79edb264


NUMBERS-33: Small changes.

Made "LanczosApproximation" public (used by "Commons Math").
Moved "Lanczos constant" staic field to appropriate class and provided accessor.


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/d79edb26
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/d79edb26
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/d79edb26

Branch: refs/heads/master
Commit: d79edb264f71db3e88779efe2681fa8c48310c3c
Parents: 1aa1ddc
Author: Gilles Sadowski <gil...@harfang.homelinux.org>
Authored: Sat May 13 16:20:25 2017 +0200
Committer: Gilles Sadowski <gil...@harfang.homelinux.org>
Committed: Sat May 13 16:20:25 2017 +0200

----------------------------------------------------------------------
 .../org/apache/commons/numbers/gamma/Gamma.java |  4 +--
 .../numbers/gamma/LanczosApproximation.java     | 11 ++++++-
 .../numbers/gamma/LanczosApproximationTest.java | 30 ++++++++++++++++++++
 3 files changed, 41 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/d79edb26/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Gamma.java
----------------------------------------------------------------------
diff --git 
a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Gamma.java
 
b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Gamma.java
index d2bb559..3fbb838 100644
--- 
a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Gamma.java
+++ 
b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Gamma.java
@@ -31,8 +31,6 @@ package org.apache.commons.numbers.gamma;
  * </p>
  */
 public class Gamma {
-    /** \( g = \frac{607}{128} \). */
-    private static final double LANCZOS_G = 607d / 128d;
     /** &radic;(2&pi;). */
     private static final double SQRT_TWO_PI = 2.506628274631000502;
 
@@ -86,7 +84,7 @@ public class Gamma {
                 return 1 / (prod * (1 + InvGamma1pm1.value(t)));
             }
         } else {
-            final double y = absX + LANCZOS_G + 0.5;
+            final double y = absX + LanczosApproximation.g() + 0.5;
             final double gammaAbs = SQRT_TWO_PI / absX *
                                     Math.pow(y, absX + 0.5) *
                                     Math.exp(-y) * 
LanczosApproximation.value(absX);

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/d79edb26/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LanczosApproximation.java
----------------------------------------------------------------------
diff --git 
a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LanczosApproximation.java
 
b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LanczosApproximation.java
index 0fad0ae..fec4ac3 100644
--- 
a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LanczosApproximation.java
+++ 
b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LanczosApproximation.java
@@ -31,7 +31,9 @@ package org.apache.commons.numbers.gamma;
  * <a href="http://my.fit.edu/~gabdo/gamma.txt";>Note on the computation
  * of the convergent Lanczos complex Gamma approximation</a>.
  */
-class LanczosApproximation {
+public class LanczosApproximation {
+    /** \( g = \frac{607}{128} \). */
+    private static final double LANCZOS_G = 607d / 128d;
     /** Lanczos coefficients. */
     private static final double[] LANCZOS = {
         0.99999999999999709182,
@@ -64,4 +66,11 @@ class LanczosApproximation {
         }
         return sum + LANCZOS[0];
     }
+
+    /**
+     * @return the Lanczos constant \( g = \frac{607}{128} \).
+     */
+    public static double g() {
+        return LANCZOS_G;
+    }
 }

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/d79edb26/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LanczosApproximationTest.java
----------------------------------------------------------------------
diff --git 
a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LanczosApproximationTest.java
 
b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LanczosApproximationTest.java
new file mode 100644
index 0000000..bd33ee0
--- /dev/null
+++ 
b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LanczosApproximationTest.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.numbers.gamma;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests for {@link LanczosApproximation}.
+ */
+public class LanczosApproximationTest {
+    @Test
+    public void testG() {
+        Assert.assertEquals(607d / 128d, LanczosApproximation.g(), 0d);
+    }
+}

Reply via email to