Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/js_backend/constant_system_javascript.dart |
| =================================================================== |
| --- sdk/lib/_internal/compiler/implementation/js_backend/constant_system_javascript.dart (revision 25000) |
| +++ sdk/lib/_internal/compiler/implementation/js_backend/constant_system_javascript.dart (working copy) |
| @@ -177,6 +177,16 @@ |
| const JavaScriptConstantSystem(); |
| /** |
| + * Returns true if the given [value] will turn into NaN or infinity |
|
karlklose
2013/07/15 13:52:08
'... true if [value] will...'?
ngeoffray
2013/07/15 13:53:38
Done.
|
| + * at runtime. |
| + */ |
| + bool integerBecomesNanOrInfinity(int value) { |
| + int absValue = value.abs(); |
|
floitsch
2013/07/15 13:25:51
Why do you need the absolute value? isNaN and isIn
ngeoffray
2013/07/15 13:49:27
Done.
|
| + double doubleValue = absValue.toDouble(); |
| + return doubleValue.isNaN || doubleValue.isInfinite; |
| + } |
| + |
| + /** |
| * Returns true if the given [value] fits into a double without losing |
| * precision. |
| */ |
| @@ -187,13 +197,20 @@ |
| return value.toDouble().floor().toInt() == value; |
| } |
| + |
|
karlklose
2013/07/15 13:52:08
Remove extra line.
ngeoffray
2013/07/15 13:53:38
Done.
|
| NumConstant convertToJavaScriptConstant(NumConstant constant) { |
| if (constant.isInt()) { |
| IntConstant intConstant = constant; |
| int intValue = intConstant.value; |
| - if (!integerFitsIntoDouble(intValue)) { |
| + if (integerBecomesNanOrInfinity(intValue)) { |
| return new DoubleConstant(intValue.toDouble()); |
| } |
| + // If the integer looses precision with JavaScript numbers, use |
|
karlklose
2013/07/15 13:52:08
'looses' -> 'loses'.
ngeoffray
2013/07/15 13:53:38
Done.
|
| + // the floored version JavaScript will use. |
| + int floorValue = intValue.toDouble().floor().toInt(); |
| + if (floorValue != intValue) { |
| + return new IntConstant(floorValue); |
| + } |
| } else if (constant.isDouble()) { |
| DoubleConstant doubleResult = constant; |
| double doubleValue = doubleResult.value; |