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

Unified Diff: runtime/lib/double.dart

Issue 9113043: Implement Double.{toString, toStringAsExponential, toStringAsPrecision} (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments and updates to status files. Created 8 years, 11 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
Index: runtime/lib/double.dart
diff --git a/runtime/lib/double.dart b/runtime/lib/double.dart
index d6006346e5781ae8457417c12910b35c5d5254c0..aa5117ccbc5045cb41ee193ac4413f9727269a73 100644
--- a/runtime/lib/double.dart
+++ b/runtime/lib/double.dart
@@ -146,11 +146,20 @@ class Double implements double {
// look at the fractionDigits first.
// Step 7.
- if (fractionDigits < 0 || fractionDigits > 20) {
+ if (fractionDigits !== null &&
+ (fractionDigits < 0 || fractionDigits > 20)) {
// TODO(antonm): should be proper RangeError or Dart counterpart.
throw "Range error";
}
+ if (isNaN()) return "NaN";
+ if (this == double.INFINITY) return "Infinity";
+ if (this == -double.INFINITY) return "-Infinity";
+
+ // The dart function prints the shortest representation when fractionDigits
+ // equals null. The native function wants -1 instead.
+ fractionDigits = (fractionDigits === null) ? -1 : fractionDigits;
+
return _toStringAsExponential(fractionDigits);
}
String _toStringAsExponential(int fractionDigits)
@@ -169,6 +178,10 @@ class Double implements double {
throw "Range error";
}
+ if (isNaN()) return "NaN";
+ if (this == double.INFINITY) return "Infinity";
+ if (this == -double.INFINITY) return "-Infinity";
+
return _toStringAsPrecision(precision);
}
String _toStringAsPrecision(int fractionDigits)

Powered by Google App Engine
This is Rietveld 408576698