Skip to content

Slider: Fixed max value miscalculation #1664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

mukulhase
Copy link
Contributor

Due to floating point precision while dividing floats followed by Math.floor().

Fixes #12852

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @dekajp, @atomiomi and @rdworth to be potential reviewers

@mukulhase
Copy link
Contributor Author

DatePicker test failure is independent of my fix.

@scottgonzalez
Copy link
Member

Please implement the logic from spinner. Arbitrary precision fixing isn't very elegant.

@mukulhase
Copy link
Contributor Author

There is a behavioral difference between the spinner and the slider, if an invalid default value(not divisible by step) is set:-

  • in the spinner, it is rounded up.
  • but in the slider, it is floored to the previous allowed value.

Hence I added the offset(instead of the spinner logic), to preserve this flooring behavior which was enforced by one of the previous test cases.
The offset solution may not be elegant, but the check after that makes it an absolute solution.
I could change the behavior to rounding-up instead of flooring(and delete the corresponding test cases).
Any suggestions?

@scottgonzalez
Copy link
Member

I'm not sure what you mean by "invalid default value" since spinner's don't have default values. Are you referring to the scenario where at the time of initialization, the associated text field has a value which results in a step mismatch? In that case, absolutely nothing is done to the value.

I can't really respond to the other part since it's based on the first part, which I don't understand. Perhaps you can clarify with a jsbin?

Due to floating point precision while dividing floats followed by Math.floor().

Fixes #12852
@mukulhase
Copy link
Contributor Author

Implemented the logic from the spinner in the latest commit. It will now round-off the max value.

@mukulhase
Copy link
Contributor Author

Is this being merged?

scottgonzalez pushed a commit that referenced this pull request Jun 9, 2016
Fixes #12852
Closes gh-1664

(cherry picked from commit a1905e2)
@jasongrout
Copy link

jasongrout commented Jan 2, 2018

This new logic still has a problem with the range (0.0, 0.6) with step 0.1: http://jsfiddle.net/f551752v/1/ - 0.6 is not reachable in this case - the slider only goes up to 0.5.

Perhaps instead of subtracting a step from max, we could build in the knowledge that the last step may not be a full step and keep the user-set maximum (since that's what the user intended, since it was explicitly set).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants