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-rng.git

commit 5a6c2f5f0402fa27efa3b2bcdd2d131a5dc971f6
Author: Alex Herbert <aherb...@apache.org>
AuthorDate: Mon Mar 4 22:41:19 2019 +0000

    RNG-79: Updated testFloat/DoubleGeneration delta.
    
    The delta is set to be within 1 or 2 ulp of 1.
---
 .../commons/rng/core/util/NumberFactoryTest.java     | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git 
a/commons-rng-core/src/test/java/org/apache/commons/rng/core/util/NumberFactoryTest.java
 
b/commons-rng-core/src/test/java/org/apache/commons/rng/core/util/NumberFactoryTest.java
index 5638768..6fb909e 100644
--- 
a/commons-rng-core/src/test/java/org/apache/commons/rng/core/util/NumberFactoryTest.java
+++ 
b/commons-rng-core/src/test/java/org/apache/commons/rng/core/util/NumberFactoryTest.java
@@ -145,10 +145,12 @@ public class NumberFactoryTest {
     public void testFloatGeneration() {
         final int allBits = 0xffffffff;
 
-        // Not capable of generating 1
-        Assert.assertEquals(1, (allBits >>> 9) * 0x1.0p-23f, 1e-6);
-        Assert.assertEquals(1, (allBits >>> 8) * 0x1.0p-24f, 1e-6);
-        Assert.assertEquals(1, Float.intBitsToFloat(0x7f << 23 | allBits >>> 
9) - 1.0f, 1e-6);
+        // Not capable of generating 1. Set the delta with 1 or 2 ULP of 1.
+        final float deltaUlp2 = 1f - Math.nextAfter(Math.nextAfter(1f, -1), 
-1);
+        final float deltaUlp1 = 1f - Math.nextAfter(1f, -1);
+        Assert.assertEquals(1, (allBits >>> 9) * 0x1.0p-23f, deltaUlp2);
+        Assert.assertEquals(1, (allBits >>> 8) * 0x1.0p-24f, deltaUlp1);
+        Assert.assertEquals(1, Float.intBitsToFloat(0x7f << 23 | allBits >>> 
9) - 1.0f, deltaUlp2);
 
         final int noBits = 0;
         Assert.assertEquals(0, (noBits >>> 9) * 0x1.0p-23f, 0);
@@ -160,10 +162,12 @@ public class NumberFactoryTest {
     public void testDoubleGeneration() {
         final long allBits = 0xffffffffffffffffL;
 
-        // Not capable of generating 1
-        Assert.assertEquals(1, (allBits >>> 12) * 0x1.0p-52d, 1e-10);
-        Assert.assertEquals(1, (allBits >>> 11) * 0x1.0p-53d, 1e-10);
-        Assert.assertEquals(1, Double.longBitsToDouble(0x3ffL << 52 | allBits 
>>> 12) - 1.0, 1e-10);
+        // Not capable of generating 1. Set the delta with 1 or 2 ULP of 1.
+        final double deltaUlp2 = 1 - Math.nextAfter(Math.nextAfter(1, -1), -1);
+        final double deltaUlp1 = 1 - Math.nextAfter(1, -1);
+        Assert.assertEquals(1, (allBits >>> 12) * 0x1.0p-52d, deltaUlp2);
+        Assert.assertEquals(1, (allBits >>> 11) * 0x1.0p-53d, deltaUlp1);
+        Assert.assertEquals(1, Double.longBitsToDouble(0x3ffL << 52 | allBits 
>>> 12) - 1.0, deltaUlp2);
 
         final long noBits = 0;
         Assert.assertEquals(0, (noBits >>> 12) * 0x1.0p-52d, 0);

Reply via email to