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

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

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 | « no previous file | runtime/lib/double.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/lib/implementation/number.js
diff --git a/compiler/lib/implementation/number.js b/compiler/lib/implementation/number.js
index b9604a7968c3dd1539661770449e7bff9ebd6fad..0a5a73cd1732a1dc9e04ac101fab9cbd11454cb5 100644
--- a/compiler/lib/implementation/number.js
+++ b/compiler/lib/implementation/number.js
@@ -156,18 +156,39 @@ function native_NumberImplementation_toDouble() {
}
function native_NumberImplementation_toString() {
- return this.toString();
+ "use strict";
+ var primitiveValue = +this;
+ // TODO(floitsch): is there a faster way to detect -0?
+ if (primitiveValue == 0 && (1 / primitiveValue) < 0) {
+ return "-0.0";
+ }
+ return "" + primitiveValue;
}
function native_NumberImplementation_toStringAsFixed(fractionDigits) {
+ var primitiveValue = +this;
+ // TODO(floitsch): is there a faster way to detect -0?
+ if (primitiveValue == 0 && (1 / primitiveValue) < 0) {
+ return "-" + this.toFixed(fractionDigits);
+ }
return this.toFixed(fractionDigits);
}
function native_NumberImplementation_toStringAsPrecision(precision) {
+ var primitiveValue = +this;
+ // TODO(floitsch): is there a faster way to detect -0?
+ if (primitiveValue == 0 && (1 / primitiveValue) < 0) {
+ return "-" + this.toPrecision(precision);
+ }
return this.toPrecision(precision);
}
function native_NumberImplementation_toStringAsExponential(fractionDigits) {
+ var primitiveValue = +this;
+ // TODO(floitsch): is there a faster way to detect -0?
+ if (primitiveValue == 0 && (1 / primitiveValue) < 0) {
+ return "-" + this.toExponential(fractionDigits);
+ }
return this.toExponential(fractionDigits);
}
« no previous file with comments | « no previous file | runtime/lib/double.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698