Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Unified Diff: compiler/lib/implementation/number.dart

Issue 8317008: Implement compareTo on DartC. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove commented line. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/corelib/corelib.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | tests/corelib/corelib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698