OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /// Test of a rounding of a common rounding bug. |
| 6 /// |
| 7 /// This bug is common in JavaScript implementations because the ECMA-262 |
| 8 /// specification of JavaScript incorrectly claims: |
| 9 /// |
| 10 /// The value of [:Math.round(x):] is the same as the value of |
| 11 /// [:Math.floor(x+0.5):], except when x is 0 or is less than 0 but greater |
| 12 /// than or equal to -0.5; for these cases [:Math.round(x):] returns 0, but |
| 13 /// [:Math.floor(x+0.5):] returns +0. |
| 14 /// |
| 15 /// However, 0.49999999999999994 + 0.5 is 1 and 9007199254740991 + 0.5 is |
| 16 /// 9007199254740992, so you cannot implement Math.round in terms of |
| 17 /// Math.floor. |
| 18 |
| 19 import 'package:expect/expect.dart'; |
| 20 |
| 21 main() { |
| 22 Expect.equals(0, (0.49999999999999994).round()); |
| 23 Expect.equals(0, (-0.49999999999999994).round()); |
| 24 |
| 25 Expect.equals(9007199254740991, (9007199254740991.0).round()); |
| 26 Expect.equals(-9007199254740991, (-9007199254740991.0).round()); |
| 27 } |
OLD | NEW |