| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // VMOptions=--optimization-counter-threshold=5 --no-background-compilation | 4 // VMOptions=--optimization-counter-threshold=5 --no-background-compilation |
| 5 | 5 |
| 6 library math_test; | 6 library math_test; |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:math'; | 8 import 'dart:math'; |
| 9 | 9 |
| 10 void checkVeryClose(double a, double b) { | 10 void checkVeryClose(double a, double b) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 if (d == dint && dint.isOdd) { | 110 if (d == dint && dint.isOdd) { |
| 111 // if `x` is -Infinity or -0.0 and `y` is an odd integer, then the | 111 // if `x` is -Infinity or -0.0 and `y` is an odd integer, then the |
| 112 // result is`-pow(-x ,y)`. | 112 // result is`-pow(-x ,y)`. |
| 113 Expect.identical(-pow(Infinity, d), pow(-Infinity, d)); | 113 Expect.identical(-pow(Infinity, d), pow(-Infinity, d)); |
| 114 Expect.identical(-pow(0.0, d), pow(-0.0, d)); | 114 Expect.identical(-pow(0.0, d), pow(-0.0, d)); |
| 115 continue; | 115 continue; |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 // if `x` is -Infinity or -0.0 and `y` is not an odd integer, then the | 118 // if `x` is -Infinity or -0.0 and `y` is not an odd integer, then the |
| 119 // result is the same as `pow(-x , y)`. | 119 // result is the same as `pow(-x , y)`. |
| 120 if (d.isNaN) { |
| 121 Expect.isTrue(pow(Infinity, d).isNaN); |
| 122 Expect.isTrue(pow(-Infinity, d).isNaN); |
| 123 Expect.isTrue(pow(0.0, d).isNaN); |
| 124 Expect.isTrue(pow(-0.0, d).isNaN); |
| 125 continue; |
| 126 } |
| 120 Expect.identical(pow(Infinity, d), pow(-Infinity, d)); | 127 Expect.identical(pow(Infinity, d), pow(-Infinity, d)); |
| 121 Expect.identical(pow(0.0, d), pow(-0.0, d)); | 128 Expect.identical(pow(0.0, d), pow(-0.0, d)); |
| 122 } | 129 } |
| 123 | 130 |
| 124 for (var d in samples) { | 131 for (var d in samples) { |
| 125 | 132 |
| 126 if (d.abs() < 1) { | 133 if (d.abs() < 1) { |
| 127 // if `y` is Infinity and the absolute value of `x` is less than 1, the | 134 // if `y` is Infinity and the absolute value of `x` is less than 1, the |
| 128 // result is 0.0. | 135 // result is 0.0. |
| 129 Expect.identical(0.0, pow(d, Infinity)); | 136 Expect.identical(0.0, pow(d, Infinity)); |
| 130 } else if (d.abs() > 1) { | 137 } else if (d.abs() > 1) { |
| 131 // if `y` is Infinity and the absolute value of `x` is greater than 1, | 138 // if `y` is Infinity and the absolute value of `x` is greater than 1, |
| 132 // the result is Infinity. | 139 // the result is Infinity. |
| 133 Expect.identical(Infinity, pow(d, Infinity)); | 140 Expect.identical(Infinity, pow(d, Infinity)); |
| 134 } else if (d == -1) { | 141 } else if (d == -1) { |
| 135 // if `y` is Infinity and `x` is -1, the result is 1.0. | 142 // if `y` is Infinity and `x` is -1, the result is 1.0. |
| 136 Expect.identical(1.0, pow(d, Infinity)); | 143 Expect.identical(1.0, pow(d, Infinity)); |
| 137 } | 144 } |
| 138 // if `y` is -Infinity, the result is `1/pow(x, Infinity)`. | 145 // if `y` is -Infinity, the result is `1/pow(x, Infinity)`. |
| 139 Expect.identical(1/pow(d, Infinity), pow(d, -Infinity)); | 146 if (d.isNaN) { |
| 147 Expect.isTrue((1/pow(d, Infinity)).isNaN); |
| 148 Expect.isTrue(pow(d, -Infinity).isNaN); |
| 149 } else { |
| 150 Expect.identical(1/pow(d, Infinity), pow(d, -Infinity)); |
| 151 } |
| 140 } | 152 } |
| 141 | 153 |
| 142 // Some non-exceptional values. | 154 // Some non-exceptional values. |
| 143 checkVeryClose(16.0, pow(4.0, 2.0)); | 155 checkVeryClose(16.0, pow(4.0, 2.0)); |
| 144 checkVeryClose(SQRT2, pow(2.0, 0.5)); | 156 checkVeryClose(SQRT2, pow(2.0, 0.5)); |
| 145 checkVeryClose(SQRT1_2, pow(0.5, 0.5)); | 157 checkVeryClose(SQRT1_2, pow(0.5, 0.5)); |
| 146 // Denormal result. | 158 // Denormal result. |
| 147 Expect.identical(5e-324, pow(2.0, -1074.0)); | 159 Expect.identical(5e-324, pow(2.0, -1074.0)); |
| 148 // Overflow. | 160 // Overflow. |
| 149 Expect.identical(Infinity, pow(10.0, 309.0)); | 161 Expect.identical(Infinity, pow(10.0, 309.0)); |
| 150 // Underflow. | 162 // Underflow. |
| 151 Expect.identical(0.0, pow(10.0, -325.0)); | 163 Expect.identical(0.0, pow(10.0, -325.0)); |
| 152 | 164 |
| 153 // Conversion to double. | 165 // Conversion to double. |
| 154 | 166 |
| 155 // The second argument is an odd integer as int, but not when converted | 167 // The second argument is an odd integer as int, but not when converted |
| 156 // to double. | 168 // to double. |
| 157 Expect.identical(Infinity, pow(-0.0, -9223372036854775809)); | 169 Expect.identical(Infinity, pow(-0.0, -9223372036854775809)); |
| 158 } | 170 } |
| 159 | 171 |
| 160 main() { | 172 main() { |
| 161 for (int i = 0; i < 10; i++) test(); | 173 for (int i = 0; i < 10; i++) test(); |
| 162 } | 174 } |
| OLD | NEW |