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) |