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

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: Updated status files. Created 8 years, 10 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 | « runtime/lib/double.cc ('k') | runtime/vm/double_conversion.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/double.dart
diff --git a/runtime/lib/double.dart b/runtime/lib/double.dart
index 65dd3e779fe09554defd0d6ad7816fe5aedd4db6..c657f14f8139607c2d966db130ce40f55cdf1825 100644
--- a/runtime/lib/double.dart
+++ b/runtime/lib/double.dart
@@ -150,11 +150,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)
@@ -173,6 +182,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)
« no previous file with comments | « runtime/lib/double.cc ('k') | runtime/vm/double_conversion.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698