sahvx655-wq commented on code in PR #410:
URL: https://github.com/apache/commons-validator/pull/410#discussion_r3510929189
##########
src/main/java/org/apache/commons/validator/routines/FloatValidator.java:
##########
@@ -68,6 +69,16 @@ public class FloatValidator extends AbstractNumberValidator {
private static final FloatValidator VALIDATOR = new FloatValidator();
+ private static boolean isFinite(final Number value) {
Review Comment:
Dropped the FloatValidator change from this PR, so this thread is moot.
Reasoning in the PR comment: the float override can't be pinned by a
JDK-portable test at 2^53.
##########
src/main/java/org/apache/commons/validator/routines/FloatValidator.java:
##########
@@ -183,6 +194,42 @@ public boolean minValue(final Float value, final float
min) {
return minValue(value.floatValue(), min);
}
+ /**
+ * Tests if the value is less than or equal to a maximum, comparing the
exact values.
+ *
+ * <p>
+ * This overrides the {@link Number} overload inherited from the
superclass, which narrows the bound to a {@code double} before comparing and so
loses
+ * precision for a {@code BigDecimal} or {@code BigInteger} bound that
carries more significant digits than a {@code double} can hold. A non-finite
+ * {@link Double} or {@link Float} operand keeps the {@code doubleValue()}
comparison so the documented infinity behaviour is unchanged.
+ * </p>
+ *
+ * @param value The value validation is being performed on.
+ * @param max The maximum value.
+ * @return {@code true} if the value is less than or equal to the maximum.
+ */
+ @Override
+ public boolean maxValue(final Number value, final Number max) {
+ return isFinite(value) && isFinite(max) ?
BigDecimal.valueOf(value.doubleValue()).compareTo(toBigDecimal(max)) <= 0 :
value.doubleValue() <= max.doubleValue();
Review Comment:
Removed the FloatValidator override entirely, so this is no longer in play.
The precision point is exactly why it can't be tested portably at that
magnitude; details in the PR comment.
--
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]