Skip to content

Slider: Fix max calculation, when step is float#1398

Closed
dekajp wants to merge 1 commit into
jquery:masterfrom
dekajp:issue_10721
Closed

Slider: Fix max calculation, when step is float#1398
dekajp wants to merge 1 commit into
jquery:masterfrom
dekajp:issue_10721

Conversation

@dekajp
Copy link
Copy Markdown
Contributor

@dekajp dekajp commented Dec 16, 2014

Fixes #10721

new _calculateNewMax method uses while loop, the cost should be very minimum
since this method is called one time in life of control, in create method or
when setOption(max) is called.

below method uses math functions to avoid loop, but this was failing
unit tests of slider_options.

TODO : to avoid while loop in Max Calculation


_calculateNewMax: function() {
  var precision = this._precision();
  var multiplier = Math.pow( 10 , precision );
  var max = this.options.max * multiplier ;
  var min = this._valueMin() * multiplier ;
  var step = this.options.step * multiplier ;
  var remainder = ( max - min ) % step;
  this.max = ( ( max - remainder ) / multiplier ).toFixed(precision);
}

@jzaefferer
Copy link
Copy Markdown
Member

@dekajp were you going to update this to address your own TODO?

@dekajp
Copy link
Copy Markdown
Contributor Author

dekajp commented Dec 23, 2014

@jzaefferer I am not planning as of now.

@dekajp
Copy link
Copy Markdown
Contributor Author

dekajp commented Dec 30, 2014

@jzaefferer i think i now know the reason why the TODO method was not working , this should fix it.
this.max = parseFloat( ( ( max - remainder ) / multiplier ).toFixed(precision) );

i will send a updated PR . i did not know toFixed was returning string. my bad

Comment thread ui/slider.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all of the extraneous parens.

scottgonzalez pushed a commit that referenced this pull request Feb 9, 2015
Fixes #10721
Closes gh-1398
(cherry picked from commit ae1d6d5)
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.

3 participants