Round Infinity with a precision argument returns Infinity (#4272)

* Round Infinity with a precision argument returns Infinity

* Also making sure this is true for -Infinity
* Tested with _.round(), _.floor() and _.ceil()

* Switch to using isFinite to check if number should be rounded

* Add tests for rounding NaN now that there is an isFinite check
This commit is contained in:
Jeff Friesen
2019-04-18 14:04:18 -06:00
committed by John-David Dalton
parent 0b8592a35c
commit 343456d696
2 changed files with 69 additions and 1 deletions

View File

@@ -5406,7 +5406,7 @@
return function(number, precision) {
number = toNumber(number);
precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
if (precision) {
if (precision && Number.isFinite(number)) {
// Shift with exponential notation to avoid floating-point issues.
// See [MDN](https://mdn.io/round#Examples) for more details.
var pair = (toString(number) + 'e').split('e'),