Skip to content
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

FloatSlider sometimes approximates the max and does show the desired range #1889

Closed
joefresna opened this issue Dec 27, 2017 · 7 comments
Closed

Comments

@joefresna
Copy link

I use ipywidgets 7.0.5 (py35_0)
Running the following code I get a widget in the range [0.2, 0.5] instead of [0.2,0.6]:
w = widgets.FloatSlider(value = 0.5, min = 0.2, max = 0.6, step = 0.1, description = "w")

@jasongrout
Copy link
Member

jasongrout commented Jan 2, 2018

Thanks for the clear and concise bug report (with an example!). I've confirmed the problem in widgets 7.1.0. I'm looking into it...

@jasongrout
Copy link
Member

This happens because of a floating point number issue, and I think the jqueryui slider we are using handles it incorrectly. When a slider's max is set, it's modified by this function: https://github.com/jquery/jquery-ui/blob/89af4c292eaa5fc1c83437ca71085264dcbef34a/ui/widgets/slider.js#L551

In that function, jqueryui tries to address roundoff error from the step by calculating what the max should be if we take the given number of steps from the min (let's call this the stepmax). However, it subtracts a whole step if the stepmax is more than the max. I think what it should do is realize that the last step may not be a full step, and set the max to what was explicitly set.

For now, a workaround is to set max to something like 0.601.

Perhaps this is another reason for us to move off of the jqueryui slider: #630.

@jasongrout
Copy link
Member

The fundamental problem we are dealing with here is that 0.1*6 = 0.6000000000000001 > 0.6 using the computer's standard floating point number representation.

@jasongrout
Copy link
Member

Reference my comment at jquery/jquery-ui#1664 (comment) - which is where the current logic is put into place.

@jasongrout
Copy link
Member

I filed a bug on their bugtracker: https://bugs.jqueryui.com/ticket/15262

@jasongrout jasongrout added this to the Future milestone Jan 4, 2018
@jasongrout
Copy link
Member

jasongrout commented Jan 4, 2018

Another thing we could do is to specifically work around the jqueryui bug by automatically setting the slider max (and min?) to something slightly different. So in this example, our code would run the same test that jqueryui runs in its code to subtract a step value, and would then (if needed) adjust the jqueryui slider max option to something slightly more than 0.6 (like 0.6 + step/10, or something) at

this.$slider.slider('option', 'max', max);
.

I think that wouldn't be too hard to implement, though it's still unfortunate that we need to do it.

I'll set this to 'good first issue' since making such a workaround is a nicely-scoped several-line solution.

@jasongrout jasongrout modified the milestones: Future, 7.1.x Jan 4, 2018
@vidartf
Copy link
Member

vidartf commented Jun 17, 2022

I have confirmed (on Binder) that the new slider package on master (slated for 8.0 release) does not have this issue. Closing as fixed.

@vidartf vidartf closed this as completed Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants