garydgregory commented on code in PR #410:
URL: https://github.com/apache/commons-validator/pull/410#discussion_r3474170191
##########
src/test/java/org/apache/commons/validator/routines/DoubleValidatorTest.java:
##########
@@ -132,6 +134,26 @@ void testDoubleRangeMinMaxNaN() {
assertFalse(validator.maxValue(Double.NaN, 20), "maxValue() NaN");
}
+ /**
+ * Test the {@link Number} range checks against a bound that carries more
precision than a {@code double}.
+ * 2^53 is the largest integer with an exact {@code double}
representation, so 2^53 + 1 cannot be narrowed
+ * onto the value: a value of 2^53 is below a minimum of 2^53 + 1 and
above a maximum of 2^53 - 0.5.
+ */
+ @Test
+ void testDoubleNumberRangeExactBound() {
+ final DoubleValidator validator = (DoubleValidator) strictValidator;
+ final long maxExactInt = 1L << 53; // 2^53
+ final Double value = Double.valueOf(maxExactInt);
+ final BigInteger above =
BigInteger.valueOf(maxExactInt).add(BigInteger.ONE); // 2^53 + 1
+ final BigInteger below =
BigInteger.valueOf(maxExactInt).subtract(BigInteger.ONE); // 2^53 - 1
+ final BigDecimal justBelow = new
BigDecimal(BigInteger.valueOf(maxExactInt)).subtract(BigDecimal.valueOf(0.5));
// 2^53 - 0.5
Review Comment:
Why is this not just `BigDecimal.valueOf(maxExactInt)` instead of `new
BigDecimal(BigInteger.valueOf(maxExactInt))` but since this is Double validator
instead of a "Big" validator is might be OK...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]