You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2017/05/10 14:39:18 UTC
commons-numbers git commit: Made functions "static".
Repository: commons-numbers
Updated Branches:
refs/heads/task_NUMBERS-33__Gamma cad5798e0 -> ef4ab3236
Made functions "static".
Removed "singleton" fields.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/ef4ab323
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/ef4ab323
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/ef4ab323
Branch: refs/heads/task_NUMBERS-33__Gamma
Commit: ef4ab32365ea7f5a0debb9f48734839b5ed00a86
Parents: cad5798
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Wed May 10 16:37:22 2017 +0200
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Wed May 10 16:37:22 2017 +0200
----------------------------------------------------------------------
.../apache/commons/numbers/gamma/Digamma.java | 2 +-
.../org/apache/commons/numbers/gamma/Gamma.java | 12 +++----
.../commons/numbers/gamma/InvGamma1pm1.java | 4 +--
.../numbers/gamma/LanczosApproximation.java | 4 +--
.../apache/commons/numbers/gamma/LogGamma.java | 17 +++-------
.../commons/numbers/gamma/LogGamma1p.java | 9 ++----
.../commons/numbers/gamma/RegularizedGamma.java | 14 ++++----
.../apache/commons/numbers/gamma/Trigamma.java | 2 +-
.../commons/numbers/gamma/DigammaTest.java | 34 +++++++++-----------
.../apache/commons/numbers/gamma/GammaTest.java | 10 +++---
.../commons/numbers/gamma/InvGamma1pm1Test.java | 8 ++---
.../commons/numbers/gamma/LogGamma1pTest.java | 8 ++---
.../commons/numbers/gamma/LogGammaTest.java | 10 +++---
.../numbers/gamma/RegularizedGammaTest.java | 4 +--
.../commons/numbers/gamma/TrigammaTest.java | 10 +++---
15 files changed, 57 insertions(+), 91 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/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 c8af00d..4caa4e7 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
@@ -58,7 +58,7 @@ public class Digamma {
* @return digamma(x) to within {@code 1e-8} relative or absolute error whichever
* is larger.
*/
- public double value(double x) {
+ public static double value(double x) {
if (Double.isNaN(x) || Double.isInfinite(x)) {
return x;
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/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 1cd5424..d2bb559 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
@@ -33,10 +33,6 @@ package org.apache.commons.numbers.gamma;
public class Gamma {
/** \( g = \frac{607}{128} \). */
private static final double LANCZOS_G = 607d / 128d;
- /** Helper. */
- private static final LanczosApproximation LANCZOS_APPROXIMATION = LanczosApproximation.instance;
- /** Helper. */
- private static final InvGamma1pm1 INV_GAMMA_1P_M1 = InvGamma1pm1.instance;
/** √(2π). */
private static final double SQRT_TWO_PI = 2.506628274631000502;
@@ -49,7 +45,7 @@ public class Gamma {
* @param x Argument.
* @return \( \Gamma(x) \)
*/
- public double value(final double x) {
+ public static double value(final double x) {
if ((x == Math.rint(x)) && (x <= 0.0)) {
return Double.NaN;
@@ -72,7 +68,7 @@ public class Gamma {
t -= 1;
prod *= t;
}
- return prod / (1 + INV_GAMMA_1P_M1.value(t - 1));
+ return prod / (1 + InvGamma1pm1.value(t - 1));
} else {
/*
* From the recurrence relation
@@ -87,13 +83,13 @@ public class Gamma {
t += 1;
prod *= t;
}
- return 1 / (prod * (1 + INV_GAMMA_1P_M1.value(t)));
+ return 1 / (prod * (1 + InvGamma1pm1.value(t)));
}
} else {
final double y = absX + LANCZOS_G + 0.5;
final double gammaAbs = SQRT_TWO_PI / absX *
Math.pow(y, absX + 0.5) *
- Math.exp(-y) * LANCZOS_APPROXIMATION.value(absX);
+ Math.exp(-y) * LanczosApproximation.value(absX);
if (x > 0) {
return gammaAbs;
} else {
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/InvGamma1pm1.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/InvGamma1pm1.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/InvGamma1pm1.java
index 43bfe2e..ab1d77b 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/InvGamma1pm1.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/InvGamma1pm1.java
@@ -22,8 +22,6 @@ package org.apache.commons.numbers.gamma;
* Class is immutable.
*/
class InvGamma1pm1 {
- /** Singleton. */
- static final InvGamma1pm1 instance = new InvGamma1pm1();
/*
* Constants copied from DGAM1 in the NSWC library.
*/
@@ -110,7 +108,7 @@ class InvGamma1pm1 {
* @return \( \frac{1}{\Gamma(1 + x)} - 1 \)
* @throws IllegalArgumentException if {@code x < -0.5} or {@code x > 1.5}
*/
- public double value(final double x) {
+ public static double value(final double x) {
if (x < -0.5 || x > 1.5) {
throw new GammaException(GammaException.OUT_OF_RANGE, x, -0.5, 1.5);
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/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 e974566..0fad0ae 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
@@ -32,8 +32,6 @@ package org.apache.commons.numbers.gamma;
* of the convergent Lanczos complex Gamma approximation</a>.
*/
class LanczosApproximation {
- /** Singleton. */
- static final LanczosApproximation instance = new LanczosApproximation();
/** Lanczos coefficients. */
private static final double[] LANCZOS = {
0.99999999999999709182,
@@ -59,7 +57,7 @@ class LanczosApproximation {
* @param x Argument.
* @return the Lanczos approximation.
*/
- public double value(final double x) {
+ public static double value(final double x) {
double sum = 0;
for (int i = LANCZOS.length - 1; i > 0; i--) {
sum += LANCZOS[i] / (x + i);
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LogGamma.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LogGamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LogGamma.java
index 6c2dd08..9698155 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LogGamma.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LogGamma.java
@@ -22,16 +22,9 @@ package org.apache.commons.numbers.gamma;
* Class is immutable.
*/
public class LogGamma {
- /** Singleton. */
- static final LogGamma instance = new LogGamma();
- /** \( g = \frac{607}{128} \). */
private static final double LANCZOS_G = 607d / 128d;
/** Performance. */
private static final double HALF_LOG_2_PI = 0.5 * Math.log(2.0 * Math.PI);
- /** Helper. */
- private static final LanczosApproximation LANCZOS_APPROXIMATION = LanczosApproximation.instance;
- /** Helper. */
- private static final LogGamma1p LOG_GAMMA_1P = LogGamma1p.instance;
/**
* Computes the function \( \ln \Gamma(x) \) for {@code x >= 0}.
@@ -52,22 +45,22 @@ public class LogGamma {
* @param x Argument.
* @return \( \ln \Gamma(x) \), or {@code NaN} if {@code x <= 0}.
*/
- public double value(double x) {
+ public static double value(double x) {
if (Double.isNaN(x) || (x <= 0.0)) {
return Double.NaN;
} else if (x < 0.5) {
- return LOG_GAMMA_1P.value(x) - Math.log(x);
+ return LogGamma1p.value(x) - Math.log(x);
} else if (x <= 2.5) {
- return LOG_GAMMA_1P.value((x - 0.5) - 0.5);
+ return LogGamma1p.value((x - 0.5) - 0.5);
} else if (x <= 8.0) {
final int n = (int) Math.floor(x - 1.5);
double prod = 1.0;
for (int i = 1; i <= n; i++) {
prod *= x - i;
}
- return LOG_GAMMA_1P.value(x - (n + 1)) + Math.log(prod);
+ return LogGamma1p.value(x - (n + 1)) + Math.log(prod);
} else {
- final double sum = LANCZOS_APPROXIMATION.value(x);
+ final double sum = LanczosApproximation.value(x);
final double tmp = x + LANCZOS_G + .5;
return ((x + .5) * Math.log(tmp)) - tmp +
HALF_LOG_2_PI + Math.log(sum / x);
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LogGamma1p.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LogGamma1p.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LogGamma1p.java
index 2f26fcc..3a9753d 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LogGamma1p.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LogGamma1p.java
@@ -22,11 +22,6 @@ package org.apache.commons.numbers.gamma;
* Class is immutable.
*/
class LogGamma1p {
- /** Singleton. */
- static final LogGamma1p instance = new LogGamma1p();
- /** Helper. */
- private static final InvGamma1pm1 invGamma1pm1 = InvGamma1pm1.instance;
-
/**
* Computes the function \( \ln \Gamma(1 + x) \) for \( -0.5 \leq x \leq 1.5 \).
*
@@ -37,11 +32,11 @@ class LogGamma1p {
* @return \( \ln \Gamma(1 + x) \)
* @throws IllegalArgumentException if {@code x < -0.5} or {@code x > 1.5}.
*/
- public double value(final double x) {
+ public static double value(final double x) {
if (x < -0.5 || x > 1.5) {
throw new GammaException(GammaException.OUT_OF_RANGE, x, -0.5, 1.5);
}
- return -Math.log1p(invGamma1pm1.value(x));
+ return -Math.log1p(InvGamma1pm1.value(x));
}
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
index 19a34a3..0231955 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
@@ -25,8 +25,6 @@ import org.apache.commons.numbers.fraction.ContinuedFraction;
* Class is immutable.
*/
public abstract class RegularizedGamma {
- /** Helper. */
- private static final LogGamma LOG_GAMMA = LogGamma.instance;
/** Maximum allowed numerical error. */
private static final double DEFAULT_EPSILON = 1e-15;
@@ -66,7 +64,7 @@ public abstract class RegularizedGamma {
*
* {@inheritDoc}
*/
- public double value(double a,
+ public static double value(double a,
double x) {
return value(a, x, DEFAULT_EPSILON, Integer.MAX_VALUE);
}
@@ -92,7 +90,7 @@ public abstract class RegularizedGamma {
*
* {@inheritDoc}
*/
- public double value(double a,
+ public static double value(double a,
double x,
double epsilon,
int maxIterations) {
@@ -127,7 +125,7 @@ public abstract class RegularizedGamma {
} else if (Double.isInfinite(sum)) {
return 1;
} else {
- return Math.exp(-x + (a * Math.log(x)) - LOG_GAMMA.value(a)) * sum;
+ return Math.exp(-x + (a * Math.log(x)) - LogGamma.value(a)) * sum;
}
}
}
@@ -145,7 +143,7 @@ public abstract class RegularizedGamma {
*
* {@inheritDoc}
*/
- public double value(double a,
+ public static double value(double a,
double x) {
return value(a, x, DEFAULT_EPSILON, Integer.MAX_VALUE);
}
@@ -168,7 +166,7 @@ public abstract class RegularizedGamma {
*
* {@inheritDoc}
*/
- public double value(final double a,
+ public static double value(final double a,
double x,
double epsilon,
int maxIterations) {
@@ -198,7 +196,7 @@ public abstract class RegularizedGamma {
}
};
- return Math.exp(-x + (a * Math.log(x)) - LOG_GAMMA.value(a)) /
+ return Math.exp(-x + (a * Math.log(x)) - LogGamma.value(a)) /
cf.evaluate(x, epsilon, maxIterations);
}
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/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 a204cb7..3c8242e 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
@@ -40,7 +40,7 @@ public class Trigamma {
* @param x Argument.
* @return trigamma(x) to within {@code 1e-8} relative or absolute error whichever is larger.
*/
- public double value(double x) {
+ public static double value(double x) {
if (Double.isNaN(x) || Double.isInfinite(x)) {
return x;
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/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 af31ab6..17b459a 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,23 +23,21 @@ 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, 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);
+ 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);
}
@Test
@@ -53,15 +51,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)], FUNCTION.value(Math.pow(10.0, -n)), 1e-8);
+ checkRelativeError(String.format("Test %.0f: ", n), expected[(int) (n - 1)], Digamma.value(Math.pow(10.0, -n)), 1e-8);
}
}
@Test
public void testDigammaNonRealArgs() {
- 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)));
+ 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)));
}
private void checkRelativeError(String msg,
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/GammaTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/GammaTest.java b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/GammaTest.java
index ec7bcb9..87bdbac 100644
--- a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/GammaTest.java
+++ b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/GammaTest.java
@@ -23,8 +23,6 @@ import org.junit.Test;
* Tests for {@link Gamma}.
*/
public class GammaTest {
- private static final Gamma FUNCTION = new Gamma();
-
/**
* Reference data for the {@link Gamma#value(double)} function. This
* data was generated with the following <a
@@ -514,7 +512,7 @@ public class GammaTest {
final double[] ref = GAMMA_REF[i];
final double x = ref[0];
final double expected = ref[1];
- final double actual = FUNCTION.value(x);
+ final double actual = Gamma.value(x);
final double absX = Math.abs(x);
final int ulps;
if (absX <= 8.0) {
@@ -536,7 +534,7 @@ public class GammaTest {
@Test
public void testGammaNegativeInteger() {
for (int i = -100; i <= 0; i++) {
- Assert.assertTrue(Integer.toString(i), Double.isNaN(FUNCTION.value(i)));
+ Assert.assertTrue(Integer.toString(i), Double.isNaN(Gamma.value(i)));
}
}
@@ -545,9 +543,9 @@ public class GammaTest {
// check that the gamma function properly switches sign
// see: https://en.wikipedia.org/wiki/Gamma_function
- double previousGamma = FUNCTION.value(-18.5);
+ double previousGamma = Gamma.value(-18.5);
for (double x = -19.5; x > -25; x -= 1.0) {
- double gamma = FUNCTION.value(x);
+ double gamma = Gamma.value(x);
Assert.assertEquals( (int) Math.signum(previousGamma),
- (int) Math.signum(gamma));
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/InvGamma1pm1Test.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/InvGamma1pm1Test.java b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/InvGamma1pm1Test.java
index 6e3c97a..ff35b9d 100644
--- a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/InvGamma1pm1Test.java
+++ b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/InvGamma1pm1Test.java
@@ -23,8 +23,6 @@ import org.junit.Test;
* Tests for {@link InvGamma1pm1}.
*/
public class InvGamma1pm1Test {
- private static final InvGamma1pm1 FUNCTION = InvGamma1pm1.instance;
-
/**
* <p>
* Reference values for the {@link Gamma#invGamma1pm1(double)} method.
@@ -73,7 +71,7 @@ public class InvGamma1pm1Test {
final double[] ref = INV_GAMMA1P_M1_REF[i];
final double x = ref[0];
final double expected = ref[1];
- final double actual = FUNCTION.value(x);
+ final double actual = InvGamma1pm1.value(x);
final double tol = ulps * Math.ulp(expected);
Assert.assertEquals(Double.toString(x), expected, actual, tol);
}
@@ -81,11 +79,11 @@ public class InvGamma1pm1Test {
@Test(expected=GammaException.class)
public void testInvGamma1pm1Precondition1() {
- FUNCTION.value(-0.51);
+ InvGamma1pm1.value(-0.51);
}
@Test(expected=GammaException.class)
public void testInvGamma1pm1Precondition2() {
- FUNCTION.value(1.51);
+ InvGamma1pm1.value(1.51);
}
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LogGamma1pTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LogGamma1pTest.java b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LogGamma1pTest.java
index ffdbe01..647ccee 100644
--- a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LogGamma1pTest.java
+++ b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LogGamma1pTest.java
@@ -23,8 +23,6 @@ import org.junit.Test;
* Tests for {@link LogGamma1p}.
*/
public class LogGamma1pTest {
- private static final LogGamma1p FUNCTION = LogGamma1p.instance;
-
private static final double[][] LOG_GAMMA1P_REF = {
{ - 0.5 , .5723649429247001 },
{ - 0.375 , .3608294954889402 },
@@ -52,7 +50,7 @@ public class LogGamma1pTest {
final double[] ref = LOG_GAMMA1P_REF[i];
final double x = ref[0];
final double expected = ref[1];
- final double actual = FUNCTION.value(x);
+ final double actual = LogGamma1p.value(x);
final double tol = ulps * Math.ulp(expected);
Assert.assertEquals(Double.toString(x), expected, actual, tol);
}
@@ -60,11 +58,11 @@ public class LogGamma1pTest {
@Test(expected=GammaException.class)
public void testLogGamma1pPrecondition1() {
- FUNCTION.value(-0.51);
+ LogGamma1p.value(-0.51);
}
@Test(expected=GammaException.class)
public void testLogGamma1pPrecondition2() {
- FUNCTION.value(1.51);
+ LogGamma1p.value(1.51);
}
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LogGammaTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LogGammaTest.java b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LogGammaTest.java
index e887ddd..0a01ddb 100644
--- a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LogGammaTest.java
+++ b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LogGammaTest.java
@@ -23,8 +23,6 @@ import org.junit.Test;
* Tests for {@link LogGamma}.
*/
public class LogGammaTest {
- private static final LogGamma FUNCTION = LogGamma.instance;
-
@Test
public void testLogGammaNan() {
testLogGamma(Double.NaN, Double.NaN);
@@ -204,7 +202,7 @@ public class LogGammaTest {
final double[] data = LOG_GAMMA_REF[i];
final double x = data[0];
final double expected = data[1];
- final double actual = FUNCTION.value(x);
+ final double actual = LogGamma.value(x);
final double tol;
if (expected == 0.0) {
tol = 1E-15;
@@ -217,16 +215,16 @@ public class LogGammaTest {
@Test
public void testLogGammaPrecondition1() {
- Assert.assertTrue(Double.isNaN(FUNCTION.value(0.0)));
+ Assert.assertTrue(Double.isNaN(LogGamma.value(0.0)));
}
@Test
public void testLogGammaPrecondition2() {
- Assert.assertTrue(Double.isNaN(FUNCTION.value(-1.0)));
+ Assert.assertTrue(Double.isNaN(LogGamma.value(-1.0)));
}
private void testLogGamma(double expected, double x) {
- double actual = FUNCTION.value(x);
+ double actual = LogGamma.value(x);
Assert.assertEquals(expected, actual, 1e-15);
}
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/RegularizedGammaTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/RegularizedGammaTest.java b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/RegularizedGammaTest.java
index ca8159c..0b0eed4 100644
--- a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/RegularizedGammaTest.java
+++ b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/RegularizedGammaTest.java
@@ -59,8 +59,8 @@ public class RegularizedGammaTest {
}
private void testRegularizedGamma(double expected, double a, double x) {
- double actualP = new RegularizedGamma.P().value(a, x);
- double actualQ = new RegularizedGamma.Q().value(a, x);
+ double actualP = RegularizedGamma.P.value(a, x);
+ double actualQ = RegularizedGamma.Q.value(a, x);
Assert.assertEquals(expected, actualP, 1e-15);
Assert.assertEquals(actualP, 1 - actualQ, 1e-15);
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ef4ab323/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 a341498..50caf0b 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,8 +23,6 @@ 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;
@@ -47,15 +45,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], FUNCTION.value(data[i]), eps);
+ Assert.assertEquals(String.format("trigamma %.0f", data[i]), data[i + 1], Trigamma.value(data[i]), eps);
}
}
@Test
public void testTrigammaNonRealArgs() {
- 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)));
+ 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)));
}
}