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

Unified Diff: runtime/lib/double.dart

Issue 8430037: Fix issue: 5427703 (compareTo), fix parsing of -0.0. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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 | runtime/vm/ast.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/double.dart
===================================================================
--- runtime/lib/double.dart (revision 1148)
+++ runtime/lib/double.dart (working copy)
@@ -103,6 +103,8 @@
bool isNaN() native "Double_isNaN";
double abs() {
+ // Handle negative 0.0.
+ if (this == 0.0) return 0.0;
return this < 0.0 ? -this : this;
}
@@ -139,7 +141,7 @@
String s = "";
// Step 6.
- if (x.isNegative()) {
+ if (x.isNegative() && x != 0.0) {
s = "-";
x = -x;
}
@@ -192,9 +194,30 @@
String toRadixString(int radix) {
throw "Double.toRadixString unimplemented.";
}
+
+ // Order is: NaN > Infinity > ... > 0.0 > -0.0 > ... > -Infinity.
int compareTo(Comparable other) {
- if (this == other) return 0;
- if (this < other) return -1;
- return 1;
+ final int EQUAL = 0, LESS = -1, GREATER = 1;
+ if (this < other) {
+ return LESS;
+ } else if (this > other) {
+ return GREATER;
+ } else if (this == other) {
+ if (this == 0.0) {
+ bool thisIsNegative = isNegative();
+ bool otherIsNegative = other.isNegative();
+ if (thisIsNegative == otherIsNegative) {
+ return EQUAL;
+ }
+ return thisIsNegative ? LESS : GREATER;
+ } else {
+ return EQUAL;
+ }
+ } else if (isNaN()) {
+ return other.isNaN() ? EQUAL : GREATER;
+ } else {
+ // Other is NaN.
+ return LESS;
+ }
}
}
« no previous file with comments | « no previous file | runtime/vm/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698