Reviewers: jarin,
Description:
Use %_IsMinusZero where applicable to replace hackery.
[email protected]
BUG=
Please review this at https://codereview.chromium.org/68453005/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+12, -19 lines):
M src/i18n.js
M src/math.js
M src/runtime.js
Index: src/i18n.js
diff --git a/src/i18n.js b/src/i18n.js
index
a64c7e67844b01ebc134956e95c2cba87cd5a288..6b563a00f915a867056e73c02856f8132226d5eb
100644
--- a/src/i18n.js
+++ b/src/i18n.js
@@ -1302,10 +1302,7 @@ function initializeNumberFormat(numberFormat,
locales, options) {
*/
function formatNumber(formatter, value) {
// Spec treats -0 and +0 as 0.
- var number = $Number(value);
- if (number === -0) {
- number = 0;
- }
+ var number = $Number(value) + 0;
return %InternalNumberFormat(formatter.formatter, number);
}
Index: src/math.js
diff --git a/src/math.js b/src/math.js
index
efab63a186d4f8b924894dad9c1f0be59ef9846a..d5cabb0efdc08ab729a099d7954efc3cb074041c
100644
--- a/src/math.js
+++ b/src/math.js
@@ -117,9 +117,8 @@ function MathMax(arg1, arg2) { // length == 2
if (arg2 > arg1) return arg2;
if (arg1 > arg2) return arg1;
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) ? arg2 : arg1;
+ // Make sure -0 is considered less than +0.
+ return (arg1 === 0 && %_IsMinusZero(arg1)) ? arg2 : arg1;
}
// All comparisons failed, one of the arguments must be NaN.
return NAN;
@@ -128,10 +127,8 @@ function MathMax(arg1, arg2) { // length == 2
for (var i = 0; i < length; i++) {
var n = %_Arguments(i);
if (!IS_NUMBER(n)) n = NonNumberToNumber(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)) {
+ // Make sure +0 is considered greater than -0.
+ if (NUMBER_IS_NAN(n) || n > r || (r === 0 && n === 0
&& %_IsMinusZero(r))) {
r = n;
}
}
@@ -147,9 +144,8 @@ function MathMin(arg1, arg2) { // length == 2
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;
+ // Make sure -0 is considered less than +0.
+ return (arg1 === 0 && %_IsMinusZero(arg1)) ? arg1 : arg2;
}
// All comparisons failed, one of the arguments must be NaN.
return NAN;
@@ -158,10 +154,8 @@ function MathMin(arg1, arg2) { // length == 2
for (var i = 0; i < length; i++) {
var n = %_Arguments(i);
if (!IS_NUMBER(n)) n = NonNumberToNumber(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)) {
+ // Make sure -0 is considered less than +0.
+ if (NUMBER_IS_NAN(n) || n < r || (r === 0 && n === 0
&& %_IsMinusZero(n))) {
r = n;
}
}
Index: src/runtime.js
diff --git a/src/runtime.js b/src/runtime.js
index
875b6b0405d64c51e4d009839b3b023b29278ca1..19b858b27ed90cce80cb5aac06b2a1ed8482bf87
100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -606,7 +606,9 @@ function SameValue(x, y) {
if (IS_NUMBER(x)) {
if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true;
// x is +0 and y is -0 or vice versa.
- if (x === 0 && y === 0 && (1 / x) != (1 / y)) return false;
+ if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) {
+ return false;
+ }
}
return x === y;
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.