OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits> | 5 #include <limits> |
6 | 6 |
7 #include "src/base/ieee754.h" | 7 #include "src/base/ieee754.h" |
8 #include "src/base/macros.h" | 8 #include "src/base/macros.h" |
9 #include "testing/gmock-support.h" | 9 #include "testing/gmock-support.h" |
10 #include "testing/gtest-support.h" | 10 #include "testing/gtest-support.h" |
11 | 11 |
12 using testing::BitEq; | 12 using testing::BitEq; |
13 using testing::IsNaN; | 13 using testing::IsNaN; |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace base { | 16 namespace base { |
17 namespace ieee754 { | 17 namespace ieee754 { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
| 21 double const kE = 2.718281828459045; |
21 double const kPI = 3.141592653589793; | 22 double const kPI = 3.141592653589793; |
22 double const kTwo120 = 1.329227995784916e+36; | 23 double const kTwo120 = 1.329227995784916e+36; |
23 | 24 |
24 } // namespace | 25 } // namespace |
25 | 26 |
26 TEST(Ieee754, Atan) { | 27 TEST(Ieee754, Atan) { |
27 EXPECT_THAT(atan(std::numeric_limits<double>::quiet_NaN()), IsNaN()); | 28 EXPECT_THAT(atan(std::numeric_limits<double>::quiet_NaN()), IsNaN()); |
28 EXPECT_THAT(atan(std::numeric_limits<double>::signaling_NaN()), IsNaN()); | 29 EXPECT_THAT(atan(std::numeric_limits<double>::signaling_NaN()), IsNaN()); |
29 EXPECT_THAT(atan(-0.0), BitEq(-0.0)); | 30 EXPECT_THAT(atan(-0.0), BitEq(-0.0)); |
30 EXPECT_THAT(atan(0.0), BitEq(0.0)); | 31 EXPECT_THAT(atan(0.0), BitEq(0.0)); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 EXPECT_EQ(0.0, exp(-std::numeric_limits<double>::infinity())); | 123 EXPECT_EQ(0.0, exp(-std::numeric_limits<double>::infinity())); |
123 EXPECT_EQ(0.0, exp(-1000)); | 124 EXPECT_EQ(0.0, exp(-1000)); |
124 EXPECT_EQ(0.0, exp(-745.1332191019412)); | 125 EXPECT_EQ(0.0, exp(-745.1332191019412)); |
125 EXPECT_EQ(2.2250738585072626e-308, exp(-708.39641853226408)); | 126 EXPECT_EQ(2.2250738585072626e-308, exp(-708.39641853226408)); |
126 EXPECT_EQ(3.307553003638408e-308, exp(-708.0)); | 127 EXPECT_EQ(3.307553003638408e-308, exp(-708.0)); |
127 EXPECT_EQ(4.9406564584124654e-324, exp(-7.45133219101941108420e+02)); | 128 EXPECT_EQ(4.9406564584124654e-324, exp(-7.45133219101941108420e+02)); |
128 EXPECT_EQ(0.36787944117144233, exp(-1.0)); | 129 EXPECT_EQ(0.36787944117144233, exp(-1.0)); |
129 EXPECT_EQ(1.0, exp(-0.0)); | 130 EXPECT_EQ(1.0, exp(-0.0)); |
130 EXPECT_EQ(1.0, exp(0.0)); | 131 EXPECT_EQ(1.0, exp(0.0)); |
131 EXPECT_EQ(1.0, exp(2.2250738585072014e-308)); | 132 EXPECT_EQ(1.0, exp(2.2250738585072014e-308)); |
| 133 |
| 134 // Test that exp(x) is monotonic near 1. |
132 EXPECT_GE(exp(1.0), exp(0.9999999999999999)); | 135 EXPECT_GE(exp(1.0), exp(0.9999999999999999)); |
133 EXPECT_LE(exp(1.0), exp(1.0000000000000002)); | 136 EXPECT_LE(exp(1.0), exp(1.0000000000000002)); |
134 EXPECT_EQ(2.718281828459045, exp(1.0)); | 137 |
| 138 // Test that we produce the correctly rounded result for 1. |
| 139 EXPECT_EQ(kE, exp(1.0)); |
| 140 |
135 EXPECT_EQ(7.38905609893065e0, exp(2.0)); | 141 EXPECT_EQ(7.38905609893065e0, exp(2.0)); |
136 EXPECT_EQ(1.7976931348622732e308, exp(7.09782712893383973096e+02)); | 142 EXPECT_EQ(1.7976931348622732e308, exp(7.09782712893383973096e+02)); |
137 EXPECT_EQ(2.6881171418161356e+43, exp(100.0)); | 143 EXPECT_EQ(2.6881171418161356e+43, exp(100.0)); |
138 EXPECT_EQ(8.218407461554972e+307, exp(709.0)); | 144 EXPECT_EQ(8.218407461554972e+307, exp(709.0)); |
139 EXPECT_EQ(1.7968190737295725e308, exp(709.7822265625e0)); | 145 EXPECT_EQ(1.7968190737295725e308, exp(709.7822265625e0)); |
140 EXPECT_EQ(std::numeric_limits<double>::infinity(), exp(709.7827128933841e0)); | 146 EXPECT_EQ(std::numeric_limits<double>::infinity(), exp(709.7827128933841e0)); |
141 EXPECT_EQ(std::numeric_limits<double>::infinity(), exp(710.0)); | 147 EXPECT_EQ(std::numeric_limits<double>::infinity(), exp(710.0)); |
142 EXPECT_EQ(std::numeric_limits<double>::infinity(), exp(1000.0)); | 148 EXPECT_EQ(std::numeric_limits<double>::infinity(), exp(1000.0)); |
143 EXPECT_EQ(std::numeric_limits<double>::infinity(), | 149 EXPECT_EQ(std::numeric_limits<double>::infinity(), |
144 exp(std::numeric_limits<double>::infinity())); | 150 exp(std::numeric_limits<double>::infinity())); |
(...skipping 16 matching lines...) Expand all Loading... |
161 TEST(Ieee754, Log) { | 167 TEST(Ieee754, Log) { |
162 EXPECT_THAT(log(std::numeric_limits<double>::quiet_NaN()), IsNaN()); | 168 EXPECT_THAT(log(std::numeric_limits<double>::quiet_NaN()), IsNaN()); |
163 EXPECT_THAT(log(std::numeric_limits<double>::signaling_NaN()), IsNaN()); | 169 EXPECT_THAT(log(std::numeric_limits<double>::signaling_NaN()), IsNaN()); |
164 EXPECT_THAT(log(-std::numeric_limits<double>::infinity()), IsNaN()); | 170 EXPECT_THAT(log(-std::numeric_limits<double>::infinity()), IsNaN()); |
165 EXPECT_THAT(log(-1.0), IsNaN()); | 171 EXPECT_THAT(log(-1.0), IsNaN()); |
166 EXPECT_EQ(-std::numeric_limits<double>::infinity(), log(-0.0)); | 172 EXPECT_EQ(-std::numeric_limits<double>::infinity(), log(-0.0)); |
167 EXPECT_EQ(-std::numeric_limits<double>::infinity(), log(0.0)); | 173 EXPECT_EQ(-std::numeric_limits<double>::infinity(), log(0.0)); |
168 EXPECT_EQ(0.0, log(1.0)); | 174 EXPECT_EQ(0.0, log(1.0)); |
169 EXPECT_EQ(std::numeric_limits<double>::infinity(), | 175 EXPECT_EQ(std::numeric_limits<double>::infinity(), |
170 log(std::numeric_limits<double>::infinity())); | 176 log(std::numeric_limits<double>::infinity())); |
| 177 |
| 178 // Test that log(E) produces the correctly rounded result. |
| 179 EXPECT_EQ(1.0, log(kE)); |
171 } | 180 } |
172 | 181 |
173 TEST(Ieee754, Log1p) { | 182 TEST(Ieee754, Log1p) { |
174 EXPECT_THAT(log1p(std::numeric_limits<double>::quiet_NaN()), IsNaN()); | 183 EXPECT_THAT(log1p(std::numeric_limits<double>::quiet_NaN()), IsNaN()); |
175 EXPECT_THAT(log1p(std::numeric_limits<double>::signaling_NaN()), IsNaN()); | 184 EXPECT_THAT(log1p(std::numeric_limits<double>::signaling_NaN()), IsNaN()); |
176 EXPECT_THAT(log1p(-std::numeric_limits<double>::infinity()), IsNaN()); | 185 EXPECT_THAT(log1p(-std::numeric_limits<double>::infinity()), IsNaN()); |
177 EXPECT_EQ(-std::numeric_limits<double>::infinity(), log1p(-1.0)); | 186 EXPECT_EQ(-std::numeric_limits<double>::infinity(), log1p(-1.0)); |
178 EXPECT_EQ(0.0, log1p(0.0)); | 187 EXPECT_EQ(0.0, log1p(0.0)); |
179 EXPECT_EQ(-0.0, log1p(-0.0)); | 188 EXPECT_EQ(-0.0, log1p(-0.0)); |
180 EXPECT_EQ(std::numeric_limits<double>::infinity(), | 189 EXPECT_EQ(std::numeric_limits<double>::infinity(), |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 EXPECT_EQ(2.910566692924059e11, tan(1048575.0 / 2.0 * kPI)); | 314 EXPECT_EQ(2.910566692924059e11, tan(1048575.0 / 2.0 * kPI)); |
306 | 315 |
307 // Test Hayne-Panek reduction. | 316 // Test Hayne-Panek reduction. |
308 EXPECT_EQ(-0.40806638884180424e0, tan(kTwo120)); | 317 EXPECT_EQ(-0.40806638884180424e0, tan(kTwo120)); |
309 EXPECT_EQ(0.40806638884180424e0, tan(-kTwo120)); | 318 EXPECT_EQ(0.40806638884180424e0, tan(-kTwo120)); |
310 } | 319 } |
311 | 320 |
312 } // namespace ieee754 | 321 } // namespace ieee754 |
313 } // namespace base | 322 } // namespace base |
314 } // namespace v8 | 323 } // namespace v8 |
OLD | NEW |