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 2019/08/08 17:30:27 UTC

[commons-numbers] 04/18: NUMBERS-120: Add mad corner case to unit tests to enforce maximum precision in doubleValue()

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

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

commit 28fa56dcb3d1f41bdc84809cd00e710d43993a01
Author: Schamschi <he...@gmx.at>
AuthorDate: Mon Jun 24 23:08:56 2019 +0200

    NUMBERS-120: Add mad corner case to unit tests to enforce maximum precision in doubleValue()
---
 .../commons/numbers/fraction/BigFractionTest.java      | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
index 7c4afdf..e20113e 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
@@ -171,11 +171,21 @@ public class BigFractionTest {
 
     @Test
     public void testDoubleValue() {
-        BigFraction first = BigFraction.of(1, 2);
-        BigFraction second = BigFraction.of(1, 3);
+        {
+            BigFraction first = BigFraction.of(1, 2);
+            BigFraction second = BigFraction.of(1, 3);
+
+            Assertions.assertEquals(0.5, first.doubleValue(), 0.0);
+            Assertions.assertEquals(1.0 / 3.0, second.doubleValue(), 0.0);
+        }
 
-        Assertions.assertEquals(0.5, first.doubleValue(), 0.0);
-        Assertions.assertEquals(1.0 / 3.0, second.doubleValue(), 0.0);
+        //NUMBERS-120
+        {
+            BigFraction f = BigFraction.of(
+                    BigInteger.ONE.shiftLeft(54),
+                    BigInteger.ONE.shiftLeft(53).add(BigInteger.ONE));
+            Assertions.assertEquals(2d - 0x1P-52, f.doubleValue());
+        }
     }
 
     @Test