commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [06/18] commons-numbers git commit: NUMBERS-33: Removed "static" keyword.
Date Thu, 11 May 2017 12:03:34 GMT
NUMBERS-33: Removed "static" keyword.

Thanks to Stian Soiland-Reyes.


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

Branch: refs/heads/master
Commit: f271063539ca219a94b37e60cdc0022ea65563e5
Parents: 871bb75
Author: Gilles Sadowski <gilles@harfang.homelinux.org>
Authored: Mon May 8 11:57:40 2017 +0200
Committer: Gilles Sadowski <gilles@harfang.homelinux.org>
Committed: Mon May 8 11:57:40 2017 +0200

----------------------------------------------------------------------
 .../apache/commons/numbers/gamma/Digamma.java   |  5 +--
 .../apache/commons/numbers/gamma/Trigamma.java  |  5 +--
 .../commons/numbers/gamma/DigammaTest.java      | 34 +++++++++++---------
 .../commons/numbers/gamma/TrigammaTest.java     | 10 +++---
 4 files changed, 26 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/f2710635/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
index 8b096d5..ddcee55 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
@@ -36,9 +36,6 @@ public class Digamma {
     /** Fraction. */
     private static final double F_1_252 = 1d / 252;
 
-    /** Class only contains a static method. */
-    private Digamma() {}
-
     /**
      * Computes the digamma function.
      *
@@ -56,7 +53,7 @@ public class Digamma {
      * @param x Argument.
      * @return digamma(x) to within \( 10^{-8} \) relative or absolute error whichever is
larger.
      */
-    public static double value(double x) {
+    public double value(double x) {
         if (Double.isNaN(x) || Double.isInfinite(x)) {
             return x;
         }

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/f2710635/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Trigamma.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Trigamma.java
b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Trigamma.java
index 9e45601..8b1c277 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Trigamma.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Trigamma.java
@@ -34,16 +34,13 @@ public class Trigamma {
     /** Fraction. */
     private static final double F_1_42 = 1d / 42;
 
-    /** Class only contains a static method. */
-    private Trigamma() {}
-
     /**
      * Computes the trigamma function.
      *
      * @param x Argument.
      * @return trigamma(x) to within \( 10^{-8} \) relative or absolute error whichever is
larger.
      */
-    public static double value(double x) {
+    public double value(double x) {
         if (Double.isNaN(x) || Double.isInfinite(x)) {
             return x;
         }

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/f2710635/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DigammaTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DigammaTest.java
b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DigammaTest.java
index 17b459a..af31ab6 100644
--- a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DigammaTest.java
+++ b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DigammaTest.java
@@ -23,21 +23,23 @@ import org.junit.Test;
  * Tests for {@link Digamma}.
  */
 public class DigammaTest {
+    private static final Digamma FUNCTION = new Digamma();
+
     @Test
     public void testDigammaLargeArgs() {
         double eps = 1e-8;
-        Assert.assertEquals(4.6001618527380874002, Digamma.value(100), eps);
-        Assert.assertEquals(3.9019896734278921970, Digamma.value(50), eps);
-        Assert.assertEquals(2.9705239922421490509, Digamma.value(20), eps);
-        Assert.assertEquals(2.9958363947076465821, Digamma.value(20.5), eps);
-        Assert.assertEquals(2.2622143570941481605, Digamma.value(10.1), eps);
-        Assert.assertEquals(2.1168588189004379233, Digamma.value(8.8), eps);
-        Assert.assertEquals(1.8727843350984671394, Digamma.value(7), eps);
-        Assert.assertEquals(0.42278433509846713939, Digamma.value(2), eps);
-        Assert.assertEquals(-100.56088545786867450, Digamma.value(0.01), eps);
-        Assert.assertEquals(-4.0390398965921882955, Digamma.value(-0.8), eps);
-        Assert.assertEquals(4.2003210041401844726, Digamma.value(-6.3), eps);
-        Assert.assertEquals(-3.110625123035E-5, Digamma.value(1.4616), eps);
+        Assert.assertEquals(4.6001618527380874002, FUNCTION.value(100), eps);
+        Assert.assertEquals(3.9019896734278921970, FUNCTION.value(50), eps);
+        Assert.assertEquals(2.9705239922421490509, FUNCTION.value(20), eps);
+        Assert.assertEquals(2.9958363947076465821, FUNCTION.value(20.5), eps);
+        Assert.assertEquals(2.2622143570941481605, FUNCTION.value(10.1), eps);
+        Assert.assertEquals(2.1168588189004379233, FUNCTION.value(8.8), eps);
+        Assert.assertEquals(1.8727843350984671394, FUNCTION.value(7), eps);
+        Assert.assertEquals(0.42278433509846713939, FUNCTION.value(2), eps);
+        Assert.assertEquals(-100.56088545786867450, FUNCTION.value(0.01), eps);
+        Assert.assertEquals(-4.0390398965921882955, FUNCTION.value(-0.8), eps);
+        Assert.assertEquals(4.2003210041401844726, FUNCTION.value(-6.3), eps);
+        Assert.assertEquals(-3.110625123035E-5, FUNCTION.value(1.4616), eps);
     }
 
     @Test
@@ -51,15 +53,15 @@ public class DigammaTest {
                 -1e+17, -1e+18, -1e+19, -1e+20, -1e+21, -1e+22, -1e+23, -1e+24, -1e+25, -1e+26,
                 -1e+27, -1e+28, -1e+29, -1e+30};
         for (double n = 1; n < 30; n++) {
-            checkRelativeError(String.format("Test %.0f: ", n), expected[(int) (n - 1)],
Digamma.value(Math.pow(10.0, -n)), 1e-8);
+            checkRelativeError(String.format("Test %.0f: ", n), expected[(int) (n - 1)],
FUNCTION.value(Math.pow(10.0, -n)), 1e-8);
         }
     }
 
     @Test
     public void testDigammaNonRealArgs() {
-        Assert.assertTrue(Double.isNaN(Digamma.value(Double.NaN)));
-        Assert.assertTrue(Double.isInfinite(Digamma.value(Double.POSITIVE_INFINITY)));
-        Assert.assertTrue(Double.isInfinite(Digamma.value(Double.NEGATIVE_INFINITY)));
+        Assert.assertTrue(Double.isNaN(FUNCTION.value(Double.NaN)));
+        Assert.assertTrue(Double.isInfinite(FUNCTION.value(Double.POSITIVE_INFINITY)));
+        Assert.assertTrue(Double.isInfinite(FUNCTION.value(Double.NEGATIVE_INFINITY)));
     }
 
     private void checkRelativeError(String msg,

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/f2710635/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/TrigammaTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/TrigammaTest.java
b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/TrigammaTest.java
index 50caf0b..a341498 100644
--- a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/TrigammaTest.java
+++ b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/TrigammaTest.java
@@ -23,6 +23,8 @@ import org.junit.Test;
  * Tests for {@link Trigamma}.
  */
 public class TrigammaTest {
+    private static final Trigamma FUNCTION = new Trigamma();
+
     @Test
     public void testTrigamma() {
         double eps = 1e-8;
@@ -45,15 +47,15 @@ public class TrigammaTest {
                 100, 0.010050166663333571395
         };
         for (int i = data.length - 2; i >= 0; i -= 2) {
-            Assert.assertEquals(String.format("trigamma %.0f", data[i]), data[i + 1], Trigamma.value(data[i]),
eps);
+            Assert.assertEquals(String.format("trigamma %.0f", data[i]), data[i + 1], FUNCTION.value(data[i]),
eps);
         }
     }
 
     @Test
     public void testTrigammaNonRealArgs() {
-        Assert.assertTrue(Double.isNaN(Trigamma.value(Double.NaN)));
-        Assert.assertTrue(Double.isInfinite(Trigamma.value(Double.POSITIVE_INFINITY)));
-        Assert.assertTrue(Double.isInfinite(Trigamma.value(Double.NEGATIVE_INFINITY)));
+        Assert.assertTrue(Double.isNaN(FUNCTION.value(Double.NaN)));
+        Assert.assertTrue(Double.isInfinite(FUNCTION.value(Double.POSITIVE_INFINITY)));
+        Assert.assertTrue(Double.isInfinite(FUNCTION.value(Double.NEGATIVE_INFINITY)));
     }
 }
 


Mime
View raw message