Index: src/math.js |
diff --git a/src/math.js b/src/math.js |
index 18492aa050c0245cd078202cbb01780d189702d6..e078ced6c0e74b225ea5a6a01b23ba2f6f761e58 100644 |
--- a/src/math.js |
+++ b/src/math.js |
@@ -119,6 +119,19 @@ function MathLog(x) { |
// ECMA 262 - 15.8.2.11 |
function MathMax(arg1, arg2) { // length == 2 |
var length = %_ArgumentsLength(); |
+ if (length == 2) { |
+ if (!IS_NUMBER(arg1)) arg1 = NonNumberToNumber(arg1); |
+ if (!IS_NUMBER(arg2)) arg2 = NonNumberToNumber(arg2); |
+ if (arg2 > arg1) return arg2; |
+ if (arg1 > arg2) return arg1; |
+ if (arg1 == arg2) { |
fschneider
2012/01/03 09:52:06
It does not make a difference for numbers, but I'd
|
+ // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be |
+ // a Smi or a heap number. |
+ return (arg1 === 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg2 : arg1; |
Lasse Reichstein
2012/01/03 06:17:45
You can drop the 1/arg1 test, and actually also th
Lasse Reichstein
2012/01/03 07:57:48
Ignore that. If you have +0 as a HeapNumber, that
|
+ } |
+ // All comparisons failed, one of the arguments must be NaN. |
+ return 0/0; // Compiler constant-folds this to NaN. |
+ } |
if (length == 0) { |
return -1/0; // Compiler constant-folds this to -Infinity. |
} |
@@ -139,6 +152,19 @@ function MathMax(arg1, arg2) { // length == 2 |
// ECMA 262 - 15.8.2.12 |
function MathMin(arg1, arg2) { // length == 2 |
var length = %_ArgumentsLength(); |
+ if (length == 2) { |
+ if (!IS_NUMBER(arg1)) arg1 = NonNumberToNumber(arg1); |
+ if (!IS_NUMBER(arg2)) arg2 = NonNumberToNumber(arg2); |
+ if (arg2 > arg1) return arg1; |
+ if (arg1 > arg2) return arg2; |
+ if (arg1 == arg2) { |
+ // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be |
+ // a Smi or a heap number. |
+ return (arg1 === 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg1 : arg2; |
Lasse Reichstein
2012/01/03 06:17:45
Here you want to return the non-smi if the values
Lasse Reichstein
2012/01/03 07:57:48
Same problem here if +0 and -0 both are non-smi, s
|
+ } |
+ // All comparisons failed, one of the arguments must be NaN. |
+ return 0/0; // Compiler constant-folds this to NaN. |
+ } |
if (length == 0) { |
return 1/0; // Compiler constant-folds this to Infinity. |
} |
@@ -149,7 +175,7 @@ function MathMin(arg1, arg2) { // length == 2 |
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 b a |
+ // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be a |
// Smi or a heap number. |
if (n < r || (r === 0 && n === 0 && !%_IsSmi(n) && 1 / n < 0)) r = n; |
} |