Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Core: Work around loss of precision from parseFloat
Fixes #15100
(cherry picked from commit b6e99eb)
  • Loading branch information
gibson042 committed Jun 7, 2014
1 parent c18c622 commit e1192af
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core.js
Expand Up @@ -216,7 +216,8 @@ jQuery.extend({
// parseFloat NaNs numeric-cast false positives (null|true|false|"")
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
// subtraction forces infinities to NaN
return !jQuery.isArray( obj ) && obj - parseFloat( obj ) >= 0;
// adding 1 corrects loss of precision from parseFloat (#15100)
return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
},

isPlainObject: function( obj ) {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/core.js
Expand Up @@ -457,7 +457,7 @@ test("isFunction", function() {
});

test( "isNumeric", function() {
expect( 37 );
expect( 38 );

var t = jQuery.isNumeric,
Traditionalists = /** @constructor */ function(n) {
Expand Down Expand Up @@ -485,6 +485,7 @@ test( "isNumeric", function() {
ok( t("4.536"), "Positive floating point string");
ok( t(-2.6), "Negative floating point number");
ok( t(3.1415), "Positive floating point number");
ok( t(1.5999999999999999), "Very precise floating point number" );
ok( t(8e5), "Exponential notation");
ok( t("123e-2"), "Exponential notation string");
ok( t(answer), "Custom .toString returning number");
Expand Down

0 comments on commit e1192af

Please sign in to comment.