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:30 UTC
[commons-numbers] 07/18: NUMBERS-120: Make doubleValue() tests
independent of double constructor
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 0c070c16f9271022ab09c8267b672987aa2c9d6e
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 27 11:52:16 2019 +0200
NUMBERS-120: Make doubleValue() tests independent of double constructor
---
.../commons/numbers/fraction/BigFractionTest.java | 56 ++++++++++++----------
1 file changed, 31 insertions(+), 25 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 e20113e..950e7cc 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
@@ -190,31 +190,37 @@ public class BigFractionTest {
@Test
public void testDoubleValueForSubnormalNumbers() {
- {
- double min = Double.MIN_VALUE;
- double min1Up = Math.nextUp(min);
- double min2Up = Math.nextUp(min1Up);
- Assertions.assertEquals(
- min,
- BigFraction.from(min).doubleValue());
- Assertions.assertEquals(
- min1Up,
- BigFraction.from(min1Up).doubleValue());
- Assertions.assertEquals(
- min2Up,
- BigFraction.from(min2Up).doubleValue());
- }
-
- {
- double minNormal1Down = Math.nextDown(Double.MIN_NORMAL);
- double minNormal2Down = Math.nextDown(minNormal1Down);
- Assertions.assertEquals(
- minNormal1Down,
- BigFraction.from(minNormal1Down).doubleValue());
- Assertions.assertEquals(
- minNormal2Down,
- BigFraction.from(minNormal2Down).doubleValue());
- }
+ Assertions.assertEquals(
+ Double.MIN_VALUE,
+ BigFraction.of(
+ BigInteger.ONE,
+ BigInteger.ONE.shiftLeft(1074)
+ ).doubleValue());
+ Assertions.assertEquals(
+ Double.MIN_VALUE * 2,
+ BigFraction.of(
+ BigInteger.valueOf(2),
+ BigInteger.ONE.shiftLeft(1074)
+ ).doubleValue());
+ Assertions.assertEquals(
+ Double.MIN_VALUE * 3,
+ BigFraction.of(
+ BigInteger.valueOf(3),
+ BigInteger.ONE.shiftLeft(1074)
+ ).doubleValue());
+
+ Assertions.assertEquals(
+ Double.MIN_NORMAL - Double.MIN_VALUE,
+ BigFraction.of(
+ BigInteger.ONE.shiftLeft(52).subtract(BigInteger.ONE),
+ BigInteger.ONE.shiftLeft(1074)
+ ).doubleValue());
+ Assertions.assertEquals(
+ Double.MIN_NORMAL - 2 * Double.MIN_VALUE,
+ BigFraction.of(
+ BigInteger.ONE.shiftLeft(52).subtract(BigInteger.valueOf(2)),
+ BigInteger.ONE.shiftLeft(1074)
+ ).doubleValue());
}
// MATH-744