You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2020/04/05 12:44:05 UTC

[commons-numbers] branch master updated (dc0071f -> f91f812)

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git.


    from dc0071f  Fixed test coverage in CombinationsTest
     new 50fcfa3  Use same javadoc for float and double Precision variants.
     new 791aa8d  Ensure the PrecisionTest covers using 0 ulps for absolute equality.
     new 62c24fe  Fix coverage in PlaneAngleTest
     new b7cd42b  Increase coverage in TrigammaTest.
     new 84f1962  Increase coverage in DigammaTest
     new f91f812  Increase coverage in RegularizedBetaTest.

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../commons/numbers/angle/PlaneAngleTest.java      | 22 ++++--------
 .../org/apache/commons/numbers/core/Precision.java | 42 ++++++++++++----------
 .../apache/commons/numbers/core/PrecisionTest.java |  2 ++
 .../apache/commons/numbers/gamma/DigammaTest.java  | 15 ++++++--
 .../commons/numbers/gamma/RegularizedBetaTest.java |  6 ++++
 .../apache/commons/numbers/gamma/TrigammaTest.java | 14 +++++++-
 6 files changed, 63 insertions(+), 38 deletions(-)


[commons-numbers] 05/06: Increase coverage in DigammaTest

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit 84f196290a6729f1570cea7ff7b198d94b19f257
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Apr 5 13:23:07 2020 +0100

    Increase coverage in DigammaTest
---
 .../org/apache/commons/numbers/gamma/DigammaTest.java     | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

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 1d708bd..02d285f 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
@@ -42,8 +42,10 @@ public class DigammaTest {
 
     @Test
     public void testDigammaSmallArgs() {
-        // values for negative powers of 10 from 1 to 30 as computed by webMathematica with 20 digits
-        // see functions.wolfram.com
+        // values for negative powers of 10 from 1 to 30 as computed by webMathematica with 20 digits.
+        // For example, to compute trigamma($i) = Polygamma(1, $i), use
+        //
+        // http://functions.wolfram.com/webMathematica/Evaluated.jsp?name=PolyGamma2&plottype=0&vars={%221%22,%22$i%22}&digits=20
         double[] expected = {-10.423754940411076795, -100.56088545786867450, -1000.5755719318103005,
             -10000.577051183514335, -100000.57719921568107, -1.0000005772140199687e6, -1.0000000577215500408e7,
             -1.0000000057721564845e8, -1.0000000005772156633e9, -1.0000000000577215665e10, -1.0000000000057721566e11,
@@ -56,6 +58,15 @@ public class DigammaTest {
     }
 
     @Test
+    public void testDigammaZero() {
+        // webMathematica states Complexinfinity.
+        // The value computed is Double.NEGATIVE_INFINITY but we leave this as a test for infinity
+        // since the next value down -Double.MIN_VALUE is Double.POSITIVE_INFINITY indicating
+        // a branch-but in the complex plane around 0.
+        Assertions.assertTrue(Double.isInfinite(Digamma.value(0.0)));
+    }
+
+    @Test
     public void testDigammaNonRealArgs() {
         Assertions.assertTrue(Double.isNaN(Digamma.value(Double.NaN)));
         Assertions.assertTrue(Double.isInfinite(Digamma.value(Double.POSITIVE_INFINITY)));


[commons-numbers] 03/06: Fix coverage in PlaneAngleTest

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit 62c24fed077ec869a5d0b5fd4a32694891ff61a6
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Apr 5 12:26:00 2020 +0100

    Fix coverage in PlaneAngleTest
---
 .../commons/numbers/angle/PlaneAngleTest.java      | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/commons-numbers-angle/src/test/java/org/apache/commons/numbers/angle/PlaneAngleTest.java b/commons-numbers-angle/src/test/java/org/apache/commons/numbers/angle/PlaneAngleTest.java
index 570edba..5cd2039 100644
--- a/commons-numbers-angle/src/test/java/org/apache/commons/numbers/angle/PlaneAngleTest.java
+++ b/commons-numbers-angle/src/test/java/org/apache/commons/numbers/angle/PlaneAngleTest.java
@@ -160,24 +160,14 @@ public class PlaneAngleTest {
     }
 
     @Test
-    public void testEquals1() {
+    public void testEquals() {
         final double value = 12345.6789;
         final PlaneAngle a = PlaneAngle.ofRadians(value);
-        final PlaneAngle b = PlaneAngle.ofRadians(value);
-        Assertions.assertEquals(a, b);
-    }
-    @Test
-    public void testEquals2() {
-        final PlaneAngle a = PlaneAngle.ofRadians(153768.373486587);
-        final PlaneAngle b = null;
-        Assertions.assertFalse(a.equals(b));
-    }
-    @Test
-    public void testEquals3() {
-        final double value = 0.987654321;
-        final PlaneAngle a = PlaneAngle.ofRadians(value);
-        final PlaneAngle b = PlaneAngle.ofRadians(value + 1e-16);
-        Assertions.assertNotEquals(a, b);
+        Assertions.assertTrue(a.equals(a));
+        Assertions.assertTrue(a.equals(PlaneAngle.ofRadians(value)));
+        Assertions.assertFalse(a.equals(PlaneAngle.ofRadians(Math.nextUp(value))));
+        Assertions.assertFalse(a.equals(new Object()));
+        Assertions.assertFalse(a.equals(null));
     }
 
     @Test


[commons-numbers] 04/06: Increase coverage in TrigammaTest.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit b7cd42b24c3c1932f5e70c7718893f73f1db45dd
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Apr 5 13:00:50 2020 +0100

    Increase coverage in TrigammaTest.
    
    This sets the allowed delta using the maximum of the relative error of
    1e8 or absolute error of 1e8 as defined in the method javadoc.
    
    It adds additional data for values below the algorithm computation
    switch point (1e5).
    
    These would fail at 1e8 absolute error but pass at 1e8 relative error as
    the result is very big.
---
 .../org/apache/commons/numbers/gamma/TrigammaTest.java     | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

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 f14fe78..1a8012f 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
@@ -30,6 +30,14 @@ public class TrigammaTest {
         //
         // http://functions.wolfram.com/webMathematica/Evaluated.jsp?name=PolyGamma2&plottype=0&vars={%221%22,%22$i%22}&digits=20
         double[] data = {
+            0.0, Double.POSITIVE_INFINITY,
+            1e-11, 1e22,
+            1e-10, 1e20,
+            1e-9, 1.0000000000000000016e18,
+            1e-8, 1.0000000000000001645e16,
+            1e-7, 1.0000000000000164493e14,
+            1e-6, 1.0000000000016449317e12,
+            1e-5, 1.0000000001644910026e10,
             1e-4, 1.0000000164469368793e8,
             1e-3, 1.0000016425331958690e6,
             1e-2, 10001.621213528313220,
@@ -45,7 +53,11 @@ public class TrigammaTest {
             100, 0.010050166663333571395
         };
         for (int i = data.length - 2; i >= 0; i -= 2) {
-            Assertions.assertEquals(data[i + 1], Trigamma.value(data[i]), eps, String.format("trigamma %.0f", data[i]));
+            final double value = data[i];
+            final double expected = data[i + 1];
+            // Allowed error is 1e-8 relative or absolute error whichever is larger.
+            final double error = Math.max(expected * eps, eps);
+            Assertions.assertEquals(expected, Trigamma.value(value), error, () -> "trigamma " + value);
         }
     }
 


[commons-numbers] 01/06: Use same javadoc for float and double Precision variants.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit 50fcfa34769917080f44f11c82c822b8fd928cbc
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Apr 5 12:04:51 2020 +0100

    Use same javadoc for float and double Precision variants.
---
 .../org/apache/commons/numbers/core/Precision.java | 42 ++++++++++++----------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Precision.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Precision.java
index 4155b51..7acce24 100644
--- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Precision.java
+++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Precision.java
@@ -184,8 +184,9 @@ public final class Precision {
     }
 
     /**
-     * Returns true if the arguments are equal or within the range of allowed
-     * error (inclusive).  Returns {@code false} if either of the arguments
+     * Returns {@code true} if there is no float value strictly between the
+     * arguments or the difference between them is within the range of allowed
+     * error (inclusive). Returns {@code false} if either of the arguments
      * is NaN.
      *
      * @param x first value
@@ -198,8 +199,9 @@ public final class Precision {
     }
 
     /**
-     * Returns true if the arguments are both NaN, are equal, or are within the range
-     * of allowed error (inclusive).
+     * Returns true if the arguments are both NaN, there are no float value strictly
+     * between the arguments or the difference between them is within the range of allowed
+     * error (inclusive).
      *
      * @param x first value
      * @param y second value
@@ -208,18 +210,22 @@ public final class Precision {
      * or both are NaN.
      */
     public static boolean equalsIncludingNaN(float x, float y, float eps) {
-        return equalsIncludingNaN(x, y) || (Math.abs(y - x) <= eps);
+        return equalsIncludingNaN(x, y, 1) || (Math.abs(y - x) <= eps);
     }
 
     /**
      * Returns true if the arguments are equal or within the range of allowed
-     * error (inclusive).
-     * Two float numbers are considered equal if there are {@code (maxUlps - 1)}
-     * (or fewer) floating point numbers between them, i.e. two adjacent floating
-     * point numbers are considered equal.
+     * error (inclusive). Returns {@code false} if either of the arguments is NaN.
+     * <p>
+     * Two double numbers are considered equal if there are {@code (maxUlps - 1)}
+     * (or fewer) floating point numbers between them, i.e. two adjacent
+     * floating point numbers are considered equal.
+     * </p>
+     * <p>
      * Adapted from <a
      * href="http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/">
-     * Bruce Dawson</a>.  Returns {@code false} if either of the arguments is NaN.
+     * Bruce Dawson</a>.
+     * </p>
      *
      * @param x first value
      * @param y second value
@@ -258,11 +264,10 @@ public final class Precision {
         }
 
         return isEqual && !Float.isNaN(x) && !Float.isNaN(y);
-
     }
 
     /**
-     * Returns true if the arguments are both NaN or if they are equal as defined
+     * Returns true if both arguments are NaN or if they are equal as defined
      * by {@link #equals(float,float,int) equals(x, y, maxUlps)}.
      *
      * @param x first value
@@ -319,8 +324,7 @@ public final class Precision {
      * @param x First value.
      * @param y Second value.
      * @param eps Amount of allowed absolute error.
-     * @return {@code true} if the values are two adjacent floating point
-     * numbers or they are within range of each other.
+     * @return {@code true} if the values are equal or within range of each other.
      */
     public static boolean equals(double x, double y, double eps) {
         return equals(x, y, 1) || Math.abs(y - x) <= eps;
@@ -350,8 +354,9 @@ public final class Precision {
     }
 
     /**
-     * Returns true if the arguments are both NaN, are equal or are within the range
-     * of allowed error (inclusive).
+     * Returns true if the arguments are both NaN, there are no double value strictly
+     * between the arguments or the difference between them is within the range of allowed
+     * error (inclusive).
      *
      * @param x first value
      * @param y second value
@@ -365,7 +370,7 @@ public final class Precision {
 
     /**
      * Returns true if the arguments are equal or within the range of allowed
-     * error (inclusive).
+     * error (inclusive). Returns {@code false} if either of the arguments is NaN.
      * <p>
      * Two float numbers are considered equal if there are {@code (maxUlps - 1)}
      * (or fewer) floating point numbers between them, i.e. two adjacent
@@ -374,7 +379,7 @@ public final class Precision {
      * <p>
      * Adapted from <a
      * href="http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/">
-     * Bruce Dawson</a>. Returns {@code false} if either of the arguments is NaN.
+     * Bruce Dawson</a>.
      * </p>
      *
      * @param x first value
@@ -414,7 +419,6 @@ public final class Precision {
         }
 
         return isEqual && !Double.isNaN(x) && !Double.isNaN(y);
-
     }
 
     /**


[commons-numbers] 06/06: Increase coverage in RegularizedBetaTest.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit f91f812e40e5928fc8cb29c1c4db27e6033465f7
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Apr 5 13:43:28 2020 +0100

    Increase coverage in RegularizedBetaTest.
---
 .../java/org/apache/commons/numbers/gamma/RegularizedBetaTest.java  | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/RegularizedBetaTest.java b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/RegularizedBetaTest.java
index 96c0813..7fdeaed 100644
--- a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/RegularizedBetaTest.java
+++ b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/RegularizedBetaTest.java
@@ -68,6 +68,12 @@ public class RegularizedBetaTest {
         testRegularizedBeta(Double.NaN, 0.5, 1.0, 0.0);
     }
 
+
+    @Test
+    public void testRegularizedBetaAboveOnePositivePositive() {
+        testRegularizedBeta(Double.NaN, 1.5, 1.0, 2.0);
+    }
+
     @Test
     public void testRegularizedBetaPositivePositivePositive() {
         testRegularizedBeta(0.75, 0.5, 1.0, 2.0);


[commons-numbers] 02/06: Ensure the PrecisionTest covers using 0 ulps for absolute equality.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit 791aa8d1f5173bf8ff34414c9559c26b044ec367
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Apr 5 12:05:27 2020 +0100

    Ensure the PrecisionTest covers using 0 ulps for absolute equality.
---
 .../src/test/java/org/apache/commons/numbers/core/PrecisionTest.java    | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/PrecisionTest.java b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/PrecisionTest.java
index ee2f90a..92e193f 100644
--- a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/PrecisionTest.java
+++ b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/PrecisionTest.java
@@ -150,6 +150,7 @@ public class PrecisionTest {
             Assertions.assertFalse(fun.equals(value, Math.nextDown(Math.nextDown(value)), 1));
             // This test is conditional
             if (!fixed1Ulp) {
+                Assertions.assertFalse(fun.equals(value, Math.nextUp(value), 0));
                 Assertions.assertTrue(fun.equals(value, Math.nextUp(Math.nextUp(value)), 2));
                 Assertions.assertTrue(fun.equals(value, Math.nextDown(Math.nextDown(value)), 2));
             }
@@ -248,6 +249,7 @@ public class PrecisionTest {
             Assertions.assertFalse(fun.equals(value, Math.nextDown(Math.nextDown(value)), 1));
             // This test is conditional
             if (!fixed1Ulp) {
+                Assertions.assertFalse(fun.equals(value, Math.nextUp(value), 0));
                 Assertions.assertTrue(fun.equals(value, Math.nextUp(Math.nextUp(value)), 2));
                 Assertions.assertTrue(fun.equals(value, Math.nextDown(Math.nextDown(value)), 2));
             }