material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[RangeSlider] Resolve issues that crash when assigning a large value to `valueTo`.

Open Park-SM opened this issue 2 years ago • 1 comments

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);
}

Park-SM avatar Jan 08 '24 08:01 Park-SM

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.

google-cla[bot] avatar Jan 08 '24 08:01 google-cla[bot]

Hi @drchen, Can i get why this PR is closed?

Park-SM avatar Mar 10 '24 13:03 Park-SM

The fix is merged https://github.com/material-components/material-components-android/commit/ac77b4cfb5ac15b37240fd455233cbca237e103f

paulfthomas avatar Mar 12 '24 16:03 paulfthomas