[RangeSlider] Resolve issues that crash when assigning a large value to `valueTo`.
Resolve the issue that crash when assigning a large value to valueTo.
The cause is the floating point rounding error.
// AS-IS
private boolean valueLandsOnTick(float value) {
// Check that the value is a multiple of stepSize given the offset of valueFrom.
return isMultipleOfStepSize(value - valueFrom);
}
// TO-BE
private boolean valueLandsOnTick(float value) {
// Check that the value is a multiple of stepSize given the offset of valueFrom.
BigDecimal bigDecimal =
new BigDecimal(Float.toString(value))
.subtract(new BigDecimal(Float.toString(valueFrom)), MathContext.DECIMAL64);
return isMultipleOfStepSizeByBigDecimal(bigDecimal);
}
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
View this failed invocation of the CLA check for more information.
For the most up to date status, view the checks section at the bottom of the pull request.
Hi @drchen, Can i get why this PR is closed?
The fix is merged https://github.com/material-components/material-components-android/commit/ac77b4cfb5ac15b37240fd455233cbca237e103f