Fix Slider snapping precision issue (#8819)#11431
Fix Slider snapping precision issue (#8819)#11431sachPundir wants to merge 1 commit intodotnet:mainfrom
Conversation
|
I don't think that's a correct approach, it will use wrong values if the tick frequency has higher precision, and the rounding number seems arbitrary. |
|
@miloush, Thanks for the clarification — you're right that snapping must remain strictly “closest tick” and not bias toward the next one. My intent was only to remove IEEE noise when the computed value is already on a tick (e.g., 1.9000000000000001). I agree arbitrary rounding could affect higher-precision TickFrequency. I’ll explore a solution based on tick-index rounding or DoubleUtil.AreClose so logical tick precision is preserved. |
|
Thanks for the feedback — that makes sense. I’ll add unit tests to cover snapping behavior and edge cases so we can validate the expected behavior more precisely before finalizing the fix. |
Fixes #8819
Description
This PR fixes floating-point precision issues in Slider snapping when TickFrequency is used.
Due to double precision limitations, calculations such as:
19 * 0.1 → 1.9000000000000001
can produce small rounding errors that affect snapping behavior.
This change ensures the final snapped value is rounded to a stable precision to avoid floating-point artifacts while preserving existing Slider logic.
Rounding is applied only to the final snapped value and does not modify Minimum, Maximum, or TickFrequency. This ensures that real precision coming from Min/Max offsets is preserved.
For example:
Minimum = 0.5001
TickFrequency = 0.1
continues to correctly produce values like 1.9001.
The intent is to remove IEEE floating-point noise, not to change logical tick precision.
Customer Impact
Improves numerical stability of Slider snapping when fractional TickFrequency values are used, resulting in more predictable snapped values.
Regression
No — this addresses a long-standing floating-point precision behavior rather than a recently introduced regression.
Testing
Risk
Low.
The change only affects the final snapped value calculation and does not alter core Slider logic or public APIs.
Microsoft Reviewers: Open in CodeFlow