Chromium Code Reviews| Index: compiler/lib/implementation/number.dart |
| diff --git a/compiler/lib/implementation/number.dart b/compiler/lib/implementation/number.dart |
| index 9dc210acee82c19581a598ac04d9e929f6064f70..168ce6c10a232adf3ddd2cf7cce9880c2eb9ec97 100644 |
| --- a/compiler/lib/implementation/number.dart |
| +++ b/compiler/lib/implementation/number.dart |
| @@ -32,11 +32,32 @@ class NumberImplementation implements int, double native "Number" { |
| // CompareTo has to give a complete order, including -0/+0, NaN and |
| // Infinities. |
| + // Order is: -Inf < .. < -0.0 < 0.0 .. < +inf < NaN. |
| NumberImplementation compareTo(NumberImplementation other) { |
| - // TODO(5427706): NumberImplementation.compareTo is broken, since it |
| - // doesn't take NaNs and -0.0 into account. |
| - // And it doesn't return an int... |
| - return this - other; |
| + // Don't use the 'this'-object, but get the native JS number. |
|
ngeoffray
2011/10/17 15:59:07
That's the call to 'toDouble'? Could you be explic
floitsch
2011/10/17 16:06:40
Done.
|
| + num thisValue = toDouble(); |
| + // Remember that NaN return false for any comparison. |
| + if (thisValue < other) { |
| + return -1; |
| + } else if (thisValue > other) { |
| + return 1; |
| + } else if (thisValue == other) { |
| + if (thisValue == 0) { |
| + bool thisIsNegative = isNegative(); |
| + bool otherIsNegative = other.isNegative(); |
| + if (thisIsNegative == otherIsNegative) return 0; |
| + if (thisIsNegative) return -1; |
| + return 1; |
| + } |
| + return 0; |
| + } else if (isNaN()) { |
| + if (other.isNaN()) { |
| + return 0; |
| + } |
| + return 1; |
| + } else { |
| + return -1; |
| + } |
| } |
| bool isNegative() native; |