diff options
Diffstat (limited to 'deps/v8/src/math.js')
-rw-r--r-- | deps/v8/src/math.js | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/deps/v8/src/math.js b/deps/v8/src/math.js index 46863284f0..aee56af4f9 100644 --- a/deps/v8/src/math.js +++ b/deps/v8/src/math.js @@ -131,16 +131,19 @@ function MathMax(arg1, arg2) { // length == 2 // All comparisons failed, one of the arguments must be NaN. return 0/0; // Compiler constant-folds this to NaN. } - var r = -1/0; // Compiler constant-folds this to -Infinity. - for (var i = 0; i < length; i++) { + if (length == 0) { + return -1/0; // Compiler constant-folds this to -Infinity. + } + var r = arg1; + if (!IS_NUMBER(r)) r = NonNumberToNumber(r); + if (NUMBER_IS_NAN(r)) return r; + for (var i = 1; i < length; i++) { var n = %_Arguments(i); if (!IS_NUMBER(n)) n = NonNumberToNumber(n); + if (NUMBER_IS_NAN(n)) return n; // Make sure +0 is considered greater than -0. -0 is never a Smi, +0 can be // a Smi or heap number. - if (NUMBER_IS_NAN(n) || n > r || - (r == 0 && n == 0 && !%_IsSmi(r) && 1 / r < 0)) { - r = n; - } + if (n > r || (r == 0 && n == 0 && !%_IsSmi(r) && 1 / r < 0)) r = n; } return r; } @@ -161,16 +164,19 @@ function MathMin(arg1, arg2) { // length == 2 // All comparisons failed, one of the arguments must be NaN. return 0/0; // Compiler constant-folds this to NaN. } - var r = 1/0; // Compiler constant-folds this to Infinity. - for (var i = 0; i < length; i++) { + if (length == 0) { + return 1/0; // Compiler constant-folds this to Infinity. + } + var r = arg1; + if (!IS_NUMBER(r)) r = NonNumberToNumber(r); + if (NUMBER_IS_NAN(r)) return r; + for (var i = 1; i < length; i++) { var n = %_Arguments(i); if (!IS_NUMBER(n)) n = NonNumberToNumber(n); + if (NUMBER_IS_NAN(n)) return n; // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be a // Smi or a heap number. - if (NUMBER_IS_NAN(n) || n < r || - (r == 0 && n == 0 && !%_IsSmi(n) && 1 / n < 0)) { - r = n; - } + if (n < r || (r == 0 && n == 0 && !%_IsSmi(n) && 1 / n < 0)) r = n; } return r; } |