OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, 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 const double PD1 = 0.0; |
| 8 const double PD2 = double.MIN_POSITIVE; |
| 9 const double PD3 = 2.0 * double.MIN_POSITIVE; |
| 10 const double PD4 = 1.18e-38; |
| 11 const double PD5 = 1.18e-38 * 2; |
| 12 const double PD6 = 0.49999999999999994; |
| 13 const double PD7 = 0.5; |
| 14 const double PD8 = 0.9999999999999999; |
| 15 const double PD9 = 1.0; |
| 16 const double PD10 = 1.000000000000001; |
| 17 const double PD11 = double.MAX_FINITE; |
| 18 |
| 19 const double ND1 = -PD1; |
| 20 const double ND2 = -PD2; |
| 21 const double ND3 = -PD3; |
| 22 const double ND4 = -PD4; |
| 23 const double ND5 = -PD5; |
| 24 const double ND6 = -PD6; |
| 25 const double ND7 = -PD7; |
| 26 const double ND8 = -PD8; |
| 27 const double ND9 = -PD9; |
| 28 const double ND10 = -PD10; |
| 29 const double ND11 = -PD11; |
| 30 |
| 31 const X1 = double.INFINITY; |
| 32 const X2 = double.NEGATIVE_INFINITY; |
| 33 const X3 = double.NAN; |
| 34 |
| 35 // The following numbers are on the border of 52 bits. |
| 36 // For example: 4503599627370499 + 0.5 => 4503599627370500. |
| 37 const PQ1 = 4503599627370496.0; |
| 38 const PQ2 = 4503599627370497.0; |
| 39 const PQ3 = 4503599627370498.0; |
| 40 const PQ4 = 4503599627370499.0; |
| 41 const PQ5 = 9007199254740991.0; |
| 42 const PQ6 = 9007199254740992.0; |
| 43 |
| 44 const NQ1 = -PQ1; |
| 45 const NQ2 = -PQ2; |
| 46 const NQ3 = -PQ3; |
| 47 const NQ4 = -PQ4; |
| 48 const NQ5 = -PQ5; |
| 49 const NQ6 = -PQ6; |
| 50 |
| 51 const int PI1 = 0; |
| 52 const int PI2 = 1; |
| 53 const int PI3 = 0x1234; |
| 54 const int PI4 = 0x12345678; |
| 55 const int PI5 = 0x123456789AB; |
| 56 const int PI6 = 0x123456789ABCDEF; |
| 57 const int PI7 = 0x123456789ABCDEF0123456789ABCDEF0123456789ABCDEF; |
| 58 |
| 59 const int NI1 = 0-PI1; |
| 60 const int NI2 = -PI2; |
| 61 const int NI3 = -PI3; |
| 62 const int NI4 = -PI4; |
| 63 const int NI5 = -PI5; |
| 64 const int NI6 = -PI6; |
| 65 const int NI7 = -PI7; |
| 66 |
| 67 |
| 68 /// Ensures that the behaviour of `action()` is the same as `value.round()`. |
| 69 @NoInline() // To ensure 'value.round()' has a non-constant receiver. |
| 70 check(value, action) { |
| 71 var result1, result2; |
| 72 try { |
| 73 result1 = value.round(); |
| 74 } catch (e) { |
| 75 result1 = e; |
| 76 } |
| 77 |
| 78 try { |
| 79 result2 = action(); |
| 80 } catch (e) { |
| 81 result2 = e; |
| 82 } |
| 83 |
| 84 Expect.equals(result1.runtimeType, result2.runtimeType); |
| 85 if (result1 is num) { |
| 86 Expect.equals(result1, result2); |
| 87 Expect.equals(result1 is int, result2 is int); |
| 88 } else { |
| 89 Expect.equals(result1.runtimeType, result2.runtimeType); |
| 90 Expect.isTrue(result1 is Error); |
| 91 } |
| 92 } |
| 93 |
| 94 @NoInline() |
| 95 void unusedCall(num x) { |
| 96 x.round(); // This call should not be removed since it might throw. |
| 97 } |
| 98 |
| 99 main() { |
| 100 check(PD1, () => PD1.round()); |
| 101 check(PD2, () => PD2.round()); |
| 102 check(PD3, () => PD3.round()); |
| 103 check(PD4, () => PD4.round()); |
| 104 check(PD5, () => PD5.round()); |
| 105 check(PD6, () => PD6.round()); |
| 106 check(PD7, () => PD7.round()); |
| 107 check(PD8, () => PD8.round()); |
| 108 check(PD9, () => PD9.round()); |
| 109 check(PD10, () => PD10.round()); |
| 110 check(PD11, () => PD11.round()); |
| 111 |
| 112 check(ND1, () => ND1.round()); |
| 113 check(ND2, () => ND2.round()); |
| 114 check(ND3, () => ND3.round()); |
| 115 check(ND4, () => ND4.round()); |
| 116 check(ND5, () => ND5.round()); |
| 117 check(ND6, () => ND6.round()); |
| 118 check(ND7, () => ND7.round()); |
| 119 check(ND8, () => ND8.round()); |
| 120 check(ND9, () => ND9.round()); |
| 121 check(ND10, () => ND10.round()); |
| 122 check(ND11, () => ND11.round()); |
| 123 |
| 124 check(X1, () => X1.round()); |
| 125 check(X2, () => X2.round()); |
| 126 check(X3, () => X3.round()); |
| 127 |
| 128 check(PQ1, () => PQ1.round()); |
| 129 check(PQ2, () => PQ2.round()); |
| 130 check(PQ3, () => PQ3.round()); |
| 131 check(PQ4, () => PQ4.round()); |
| 132 check(PQ5, () => PQ5.round()); |
| 133 check(PQ6, () => PQ6.round()); |
| 134 |
| 135 check(NQ1, () => NQ1.round()); |
| 136 check(NQ2, () => NQ2.round()); |
| 137 check(NQ3, () => NQ3.round()); |
| 138 check(NQ4, () => NQ4.round()); |
| 139 check(NQ5, () => NQ5.round()); |
| 140 check(NQ6, () => NQ6.round()); |
| 141 |
| 142 check(PI1, () => PI1.round()); |
| 143 check(PI2, () => PI2.round()); |
| 144 check(PI3, () => PI3.round()); |
| 145 check(PI4, () => PI4.round()); |
| 146 check(PI5, () => PI5.round()); |
| 147 check(PI6, () => PI6.round()); |
| 148 check(PI7, () => PI7.round()); |
| 149 |
| 150 check(NI1, () => NI1.round()); |
| 151 check(NI2, () => NI2.round()); |
| 152 check(NI3, () => NI3.round()); |
| 153 check(NI4, () => NI4.round()); |
| 154 check(NI5, () => NI5.round()); |
| 155 check(NI6, () => NI6.round()); |
| 156 check(NI7, () => NI7.round()); |
| 157 |
| 158 // Check that the operation is not removed if it can throw, even if the result |
| 159 // is unused. |
| 160 Expect.throws(() { X1.round(); }); |
| 161 Expect.throws(() { X2.round(); }); |
| 162 Expect.throws(() { X3.round(); }); |
| 163 unusedCall(0); |
| 164 Expect.throws(() { unusedCall(X1); }); |
| 165 Expect.throws(() { unusedCall(X2); }); |
| 166 Expect.throws(() { unusedCall(X3); }); |
| 167 } |
OLD | NEW |