Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/lib/js_number.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/lib/js_number.dart b/sdk/lib/_internal/compiler/implementation/lib/js_number.dart |
| index 6acf7696feef9b2df4fe6ee65bc927195b90d985..bfc3343e46ee96745050a5b346b134a5eb0138e9 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/lib/js_number.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/lib/js_number.dart |
| @@ -49,28 +49,36 @@ class JSNumber { |
| num abs() => JS('num', r'Math.abs(#)', this); |
| - int toInt() { |
| + num ceil() { |
| if (isNaN) throw new FormatException('NaN'); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
Consider UnsupportedError.
FormatException is real
|
| if (isInfinite) throw new FormatException('Infinity'); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
Consider combining the test into one 'Not finite'
|
| - num truncated = truncate(); |
| - return JS('bool', r'# == -0.0', truncated) ? 0 : truncated; |
| + num ceiled = JS('num', r'Math.ceil(#)', this); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
Just do:
return JS('num', r'Math.ceil(#) + 0', t
|
| + return (ceiled == -0.0) ? 0 : ceiled; |
| } |
| - num ceil() => JS('num', r'Math.ceil(#)', this); |
| - |
| - num floor() => JS('num', r'Math.floor(#)', this); |
| + num floor() { |
| + if (isNaN) throw new FormatException('NaN'); |
| + if (isInfinite) throw new FormatException('Infinity'); |
| + JS('num', r'Math.floor(#)', this); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
This can return -0 if it gets -0 as input. Add the
|
| + } |
| - bool get isInfinite { |
| - return JS('bool', r'# == Infinity', this) |
| - || JS('bool', r'# == -Infinity', this); |
| + int truncate() { |
| + return this < 0 ? ceil() : floor(); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
Parentheses around (this < 0).
|
| } |
| num round() { |
| - if (this < 0) { |
| - return JS('num', r'-Math.round(-#)', this); |
| - } else { |
| - return JS('num', r'Math.round(#)', this); |
| + if (isNaN) throw new FormatException('NaN'); |
| + if (isInfinite) throw new FormatException('Infinity'); |
| + if (this <= 0) { |
| + num rounded = JS('num', r'-Math.round(-#)', this); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
Just do
return JS('int', r'-Math.round(-#) + 0'
|
| + return (rounded == -0.0) ? 0 : rounded; |
| } |
| + return JS('num', r'Math.round(#)', this); |
| + } |
| + |
| + bool get isInfinite { |
| + return JS('bool', r'# == Infinity', this) |
| + || JS('bool', r'# == -Infinity', this); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
Indentation off here.
|
| } |
| num clamp(lowerLimit, upperLimit) { |
| @@ -86,8 +94,6 @@ class JSNumber { |
| double toDouble() => this; |
| - num truncate() => this < 0 ? ceil() : floor(); |
| - |
| String toStringAsFixed(int fractionDigits) { |
| checkNum(fractionDigits); |
| // TODO(floitsch): fractionDigits must be an integer. |