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 | |
7 // Don't convert !(a op b) to (a neg-op b) when a or b might be NaN. | 5 // Don't convert !(a op b) to (a neg-op b) when a or b might be NaN. |
8 test(double n) { | 6 test(double n) { |
9 // Force known type to double, preserves NaN. | 7 // Force known type to double, preserves NaN. |
10 n = 0.0 + n; | 8 n = 0.0 + n; |
11 Expect.isFalse(n >= 0); | 9 Expect.isFalse(n >= 0); |
12 Expect.isTrue(!(n < 0)); | 10 Expect.isTrue(!(n < 0)); |
13 | 11 |
14 Expect.isFalse(n <= 0); | 12 Expect.isFalse(n <= 0); |
15 Expect.isTrue(!(n > 0)); | 13 Expect.isTrue(!(n > 0)); |
16 | 14 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 main() { | 108 main() { |
111 test(hideConstant(27, double.NAN)); | 109 test(hideConstant(27, double.NAN)); |
112 testConstant(); | 110 testConstant(); |
113 } | 111 } |
114 | 112 |
115 double hideConstant(int n, double result) { | 113 double hideConstant(int n, double result) { |
116 if (n == 1) return result; | 114 if (n == 1) return result; |
117 if ((n & 1) == 0) return hideConstant(n >> 1, result); | 115 if ((n & 1) == 0) return hideConstant(n >> 1, result); |
118 return hideConstant(3 * n + 1, result); | 116 return hideConstant(3 * n + 1, result); |
119 } | 117 } |
OLD | NEW |