Ensure round methods don't return NaN for large precision values.

This commit is contained in:
John-David Dalton
2016-05-20 08:08:39 -07:00
parent 14a16c2a7a
commit 68ae6fc212
2 changed files with 15 additions and 1 deletions

View File

@@ -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.

View File

@@ -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);
});
});
/*--------------------------------------------------------------------------*/