From 68ae6fc2122c4ea23ae42f9b176e20cffde2d7ba Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 20 May 2016 08:08:39 -0700 Subject: [PATCH] Ensure round methods don't return `NaN` for large `precision` values. --- lodash.js | 2 +- test/test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index c6006e01f..1fb7ef80e 100644 --- a/lodash.js +++ b/lodash.js @@ -4912,7 +4912,7 @@ var func = Math[methodName]; return function(number, precision) { number = toNumber(number); - precision = toInteger(precision); + precision = nativeMin(toInteger(precision), 292); if (precision) { // Shift with exponential notation to avoid floating-point issues. // See [MDN](https://mdn.io/round#Examples) for more details. diff --git a/test/test.js b/test/test.js index 6f902850a..e05944503 100644 --- a/test/test.js +++ b/test/test.js @@ -19661,6 +19661,20 @@ assert.deepEqual(actual, expected); }); + + QUnit.test('`_.' + methodName + '` should not return `NaN` for large `precision` values', function(assert) { + assert.expect(1); + + var results = [ + _.round(10.0000001, 1000), + _.round(MAX_SAFE_INTEGER, 293) + ]; + + var expected = lodashStable.map(results, stubFalse), + actual = lodashStable.map(results, lodashStable.isNaN); + + assert.deepEqual(actual, expected); + }); }); /*--------------------------------------------------------------------------*/