mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 18:36:29 +00:00
[dart2wasm] Minor fixes for double string functions.
Change-Id: Ia5165712ee8469699a7c9bf58b0fe86417b1b3d5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265406 Commit-Queue: Ömer Ağacan <omersa@google.com> Reviewed-by: Ömer Ağacan <omersa@google.com>
This commit is contained in:
parent
e70dec4e82
commit
bd75b2c9e1
|
@ -194,10 +194,20 @@ class _BoxedDouble implements double {
|
|||
}
|
||||
}
|
||||
// TODO(koda): Consider optimizing all small integral values.
|
||||
if (identical(0.0, this)) {
|
||||
return "0.0";
|
||||
if (isNaN) return "NaN";
|
||||
if (this == double.infinity) return "Infinity";
|
||||
if (this == -double.infinity) return "-Infinity";
|
||||
if (this == 0) {
|
||||
if (isNegative) {
|
||||
return "-0.0";
|
||||
} else {
|
||||
return "0.0";
|
||||
}
|
||||
}
|
||||
String result = _doubleToString(value);
|
||||
if (this % 1.0 == 0.0 && result.indexOf('e') == -1) {
|
||||
result = '$result.0';
|
||||
}
|
||||
// Replace the least recently inserted entry.
|
||||
_cache[_cacheEvictIndex] = this;
|
||||
_cache[_cacheEvictIndex + 1] = result;
|
||||
|
@ -218,6 +228,8 @@ class _BoxedDouble implements double {
|
|||
|
||||
// Step 4.
|
||||
if (isNaN) return "NaN";
|
||||
if (this == double.infinity) return "Infinity";
|
||||
if (this == -double.infinity) return "-Infinity";
|
||||
|
||||
// Step 5 and 6 skipped. Will be dealt with by native function.
|
||||
|
||||
|
@ -226,7 +238,9 @@ class _BoxedDouble implements double {
|
|||
return x.toString();
|
||||
}
|
||||
|
||||
return _toStringAsFixed(fractionDigits);
|
||||
String result = _toStringAsFixed(fractionDigits);
|
||||
if (this == 0 && isNegative) return '-$result';
|
||||
return result;
|
||||
}
|
||||
|
||||
String _toStringAsFixed(int fractionDigits) =>
|
||||
|
@ -250,7 +264,9 @@ class _BoxedDouble implements double {
|
|||
if (this == double.infinity) return "Infinity";
|
||||
if (this == -double.infinity) return "-Infinity";
|
||||
|
||||
return _toStringAsExponential(fractionDigits);
|
||||
String result = _toStringAsExponential(fractionDigits);
|
||||
if (this == 0 && isNegative) return '-$result';
|
||||
return result;
|
||||
}
|
||||
|
||||
String _toStringAsExponential(int? fractionDigits) {
|
||||
|
@ -277,7 +293,9 @@ class _BoxedDouble implements double {
|
|||
if (this == double.infinity) return "Infinity";
|
||||
if (this == -double.infinity) return "-Infinity";
|
||||
|
||||
return _toStringAsPrecision(precision);
|
||||
String result = _toStringAsPrecision(precision);
|
||||
if (this == 0 && isNegative) return '-$result';
|
||||
return result;
|
||||
}
|
||||
|
||||
String _toStringAsPrecision(int fractionDigits) =>
|
||||
|
|
Loading…
Reference in a new issue