From: Richard Gibson Date: Sat, 7 Jun 2014 18:22:49 +0000 (-0400) Subject: Core: Work around loss of precision from parseFloat X-Git-Tag: 1.11.2~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b6e99eb43c35a3cd048c5c56d31c7e871f299a77;p=jquery.git Core: Work around loss of precision from parseFloat Fixes #15100 --- diff --git a/src/core.js b/src/core.js index d3501041e..028d0ac02 100644 --- a/src/core.js +++ b/src/core.js @@ -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; }, isEmptyObject: function( obj ) { diff --git a/test/unit/core.js b/test/unit/core.js index b2a0b880e..79cbd0d54 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -462,7 +462,7 @@ test("isFunction", function() { }); test( "isNumeric", function() { - expect( 37 ); + expect( 38 ); var t = jQuery.isNumeric, Traditionalists = /** @constructor */ function(n) { @@ -490,6 +490,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");