mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Ensure round methods don't return NaN for large precision values.
This commit is contained in:
@@ -4912,7 +4912,7 @@
|
|||||||
var func = Math[methodName];
|
var func = Math[methodName];
|
||||||
return function(number, precision) {
|
return function(number, precision) {
|
||||||
number = toNumber(number);
|
number = toNumber(number);
|
||||||
precision = toInteger(precision);
|
precision = nativeMin(toInteger(precision), 292);
|
||||||
if (precision) {
|
if (precision) {
|
||||||
// Shift with exponential notation to avoid floating-point issues.
|
// Shift with exponential notation to avoid floating-point issues.
|
||||||
// See [MDN](https://mdn.io/round#Examples) for more details.
|
// See [MDN](https://mdn.io/round#Examples) for more details.
|
||||||
|
|||||||
14
test/test.js
14
test/test.js
@@ -19661,6 +19661,20 @@
|
|||||||
|
|
||||||
assert.deepEqual(actual, expected);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user