OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
| 5 import "package:expect/expect.dart"; |
| 6 |
5 // Don't convert !(a op b) to (a neg-op b) when a or b might be NaN. | 7 // Don't convert !(a op b) to (a neg-op b) when a or b might be NaN. |
6 test(double n) { | 8 test(double n) { |
7 // Force known type to double, preserves NaN. | 9 // Force known type to double, preserves NaN. |
8 n = 0.0 + n; | 10 n = 0.0 + n; |
9 Expect.isFalse(n >= 0); | 11 Expect.isFalse(n >= 0); |
10 Expect.isTrue(!(n < 0)); | 12 Expect.isTrue(!(n < 0)); |
11 | 13 |
12 Expect.isFalse(n <= 0); | 14 Expect.isFalse(n <= 0); |
13 Expect.isTrue(!(n > 0)); | 15 Expect.isTrue(!(n > 0)); |
14 | 16 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 main() { | 110 main() { |
109 test(hideConstant(27, double.NAN)); | 111 test(hideConstant(27, double.NAN)); |
110 testConstant(); | 112 testConstant(); |
111 } | 113 } |
112 | 114 |
113 double hideConstant(int n, double result) { | 115 double hideConstant(int n, double result) { |
114 if (n == 1) return result; | 116 if (n == 1) return result; |
115 if ((n & 1) == 0) return hideConstant(n >> 1, result); | 117 if ((n & 1) == 0) return hideConstant(n >> 1, result); |
116 return hideConstant(3 * n + 1, result); | 118 return hideConstant(3 * n + 1, result); |
117 } | 119 } |
OLD | NEW |