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 import 'package:expect/expect.dart'; | |
6 | |
7 main() { | |
8 Expect.equals(0.0, 0.0.truncateToDouble()); | |
9 Expect.equals(0.0, double.MIN_POSITIVE.truncateToDouble()); | |
10 Expect.equals(0.0, (2.0 * double.MIN_POSITIVE).truncateToDouble()); | |
11 Expect.equals(0.0, (1.18e-38).truncateToDouble()); | |
12 Expect.equals(0.0, (1.18e-38 * 2).truncateToDouble()); | |
13 Expect.equals(0.0, 0.49999999999999994.truncateToDouble()); | |
14 Expect.equals(0.0, 0.5.truncateToDouble()); | |
15 Expect.equals(0.0, 0.9999999999999999.truncateToDouble()); | |
16 Expect.equals(1.0, 1.0.truncateToDouble()); | |
17 Expect.equals(1.0, 1.000000000000001.truncateToDouble()); | |
18 // The following numbers are on the border of 52 bits. | |
19 // For example: 4503599627370499 + 0.5 => 4503599627370500. | |
20 Expect.equals(4503599627370496.0, 4503599627370496.0.truncateToDouble()); | |
21 Expect.equals(4503599627370497.0, 4503599627370497.0.truncateToDouble()); | |
22 Expect.equals(4503599627370498.0, 4503599627370498.0.truncateToDouble()); | |
23 Expect.equals(4503599627370499.0, 4503599627370499.0.truncateToDouble()); | |
24 | |
25 Expect.equals(9007199254740991.0, 9007199254740991.0.truncateToDouble()); | |
26 Expect.equals(9007199254740992.0, 9007199254740992.0.truncateToDouble()); | |
27 Expect.equals(double.MAX_FINITE, double.MAX_FINITE.truncateToDouble()); | |
28 | |
29 Expect.equals(0.0, (-double.MIN_POSITIVE).truncateToDouble()); | |
30 Expect.equals(0.0, (2.0 * -double.MIN_POSITIVE).truncateToDouble()); | |
31 Expect.equals(0.0, (-1.18e-38).truncateToDouble()); | |
32 Expect.equals(0.0, (-1.18e-38 * 2).truncateToDouble()); | |
33 Expect.equals(0.0, (-0.49999999999999994).truncateToDouble()); | |
34 Expect.equals(0.0, (-0.5).truncateToDouble()); | |
35 Expect.equals(0.0, (-0.9999999999999999).truncateToDouble()); | |
36 Expect.equals(-1.0, (-1.0).truncateToDouble()); | |
37 Expect.equals(-1.0, (-1.000000000000001).truncateToDouble()); | |
38 Expect.equals(-4503599627370496.0, (-4503599627370496.0).truncateToDouble()); | |
39 Expect.equals(-4503599627370497.0, (-4503599627370497.0).truncateToDouble()); | |
40 Expect.equals(-4503599627370498.0, (-4503599627370498.0).truncateToDouble()); | |
41 Expect.equals(-4503599627370499.0, (-4503599627370499.0).truncateToDouble()); | |
42 Expect.equals(-9007199254740991.0, (-9007199254740991.0).truncateToDouble()); | |
43 Expect.equals(-9007199254740992.0, (-9007199254740992.0).truncateToDouble()); | |
44 Expect.equals(-double.MAX_FINITE, (-double.MAX_FINITE).truncateToDouble()); | |
45 | |
46 Expect.equals(double.INFINITY, double.INFINITY.truncateToDouble()); | |
47 Expect.equals( | |
48 double.NEGATIVE_INFINITY, double.NEGATIVE_INFINITY.truncateToDouble()); | |
49 Expect.isTrue(double.NAN.truncateToDouble().isNaN); | |
50 | |
51 Expect.isTrue(0.0.truncateToDouble() is double); | |
52 Expect.isTrue(double.MIN_POSITIVE.truncateToDouble() is double); | |
53 Expect.isTrue((2.0 * double.MIN_POSITIVE).truncateToDouble() is double); | |
54 Expect.isTrue((1.18e-38).truncateToDouble() is double); | |
55 Expect.isTrue((1.18e-38 * 2).truncateToDouble() is double); | |
56 Expect.isTrue(0.49999999999999994.truncateToDouble() is double); | |
57 Expect.isTrue(0.5.truncateToDouble() is double); | |
58 Expect.isTrue(0.9999999999999999.truncateToDouble() is double); | |
59 Expect.isTrue(1.0.truncateToDouble() is double); | |
60 Expect.isTrue(1.000000000000001.truncateToDouble() is double); | |
61 Expect.isTrue(4503599627370496.0.truncateToDouble() is double); | |
62 Expect.isTrue(4503599627370497.0.truncateToDouble() is double); | |
63 Expect.isTrue(4503599627370498.0.truncateToDouble() is double); | |
64 Expect.isTrue(4503599627370499.0.truncateToDouble() is double); | |
65 Expect.isTrue(9007199254740991.0.truncateToDouble() is double); | |
66 Expect.isTrue(9007199254740992.0.truncateToDouble() is double); | |
67 Expect.isTrue(double.MAX_FINITE.truncateToDouble() is double); | |
68 | |
69 Expect.isTrue((-double.MIN_POSITIVE).truncateToDouble() is double); | |
70 Expect.isTrue((2.0 * -double.MIN_POSITIVE).truncateToDouble() is double); | |
71 Expect.isTrue((-1.18e-38).truncateToDouble() is double); | |
72 Expect.isTrue((-1.18e-38 * 2).truncateToDouble() is double); | |
73 Expect.isTrue((-0.49999999999999994).truncateToDouble() is double); | |
74 Expect.isTrue((-0.5).truncateToDouble() is double); | |
75 Expect.isTrue((-0.9999999999999999).truncateToDouble() is double); | |
76 Expect.isTrue((-1.0).truncateToDouble() is double); | |
77 Expect.isTrue((-1.000000000000001).truncateToDouble() is double); | |
78 Expect.isTrue((-4503599627370496.0).truncateToDouble() is double); | |
79 Expect.isTrue((-4503599627370497.0).truncateToDouble() is double); | |
80 Expect.isTrue((-4503599627370498.0).truncateToDouble() is double); | |
81 Expect.isTrue((-4503599627370499.0).truncateToDouble() is double); | |
82 Expect.isTrue((-9007199254740991.0).truncateToDouble() is double); | |
83 Expect.isTrue((-9007199254740992.0).truncateToDouble() is double); | |
84 Expect.isTrue((-double.MAX_FINITE).truncateToDouble() is double); | |
85 } | |
OLD | NEW |