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" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 EXPECT_EQ(-0.7071067811865467, cos(11.0 / 4 * kPI)); | 110 EXPECT_EQ(-0.7071067811865467, cos(11.0 / 4 * kPI)); |
111 EXPECT_EQ(-0.7071067811865471, cos(13.0 / 4 * kPI)); | 111 EXPECT_EQ(-0.7071067811865471, cos(13.0 / 4 * kPI)); |
112 EXPECT_EQ(0.9367521275331447, cos(1000000.0)); | 112 EXPECT_EQ(0.9367521275331447, cos(1000000.0)); |
113 EXPECT_EQ(-3.435757038074824e-12, cos(1048575.0 / 2 * kPI)); | 113 EXPECT_EQ(-3.435757038074824e-12, cos(1048575.0 / 2 * kPI)); |
114 | 114 |
115 // Test Hayne-Panek reduction. | 115 // Test Hayne-Panek reduction. |
116 EXPECT_EQ(-0.9258790228548379e0, cos(kTwo120)); | 116 EXPECT_EQ(-0.9258790228548379e0, cos(kTwo120)); |
117 EXPECT_EQ(-0.9258790228548379e0, cos(-kTwo120)); | 117 EXPECT_EQ(-0.9258790228548379e0, cos(-kTwo120)); |
118 } | 118 } |
119 | 119 |
| 120 TEST(Ieee754, Cosh) { |
| 121 // Test values mentioned in the EcmaScript spec. |
| 122 EXPECT_THAT(cosh(std::numeric_limits<double>::quiet_NaN()), IsNaN()); |
| 123 EXPECT_THAT(cosh(std::numeric_limits<double>::signaling_NaN()), IsNaN()); |
| 124 EXPECT_THAT(cosh(std::numeric_limits<double>::infinity()), |
| 125 std::numeric_limits<double>::infinity()); |
| 126 EXPECT_THAT(cosh(-std::numeric_limits<double>::infinity()), |
| 127 std::numeric_limits<double>::infinity()); |
| 128 EXPECT_EQ(1, cosh(0.0)); |
| 129 EXPECT_EQ(1, cosh(-0.0)); |
| 130 } |
| 131 |
120 TEST(Ieee754, Exp) { | 132 TEST(Ieee754, Exp) { |
121 EXPECT_THAT(exp(std::numeric_limits<double>::quiet_NaN()), IsNaN()); | 133 EXPECT_THAT(exp(std::numeric_limits<double>::quiet_NaN()), IsNaN()); |
122 EXPECT_THAT(exp(std::numeric_limits<double>::signaling_NaN()), IsNaN()); | 134 EXPECT_THAT(exp(std::numeric_limits<double>::signaling_NaN()), IsNaN()); |
123 EXPECT_EQ(0.0, exp(-std::numeric_limits<double>::infinity())); | 135 EXPECT_EQ(0.0, exp(-std::numeric_limits<double>::infinity())); |
124 EXPECT_EQ(0.0, exp(-1000)); | 136 EXPECT_EQ(0.0, exp(-1000)); |
125 EXPECT_EQ(0.0, exp(-745.1332191019412)); | 137 EXPECT_EQ(0.0, exp(-745.1332191019412)); |
126 EXPECT_EQ(2.2250738585072626e-308, exp(-708.39641853226408)); | 138 EXPECT_EQ(2.2250738585072626e-308, exp(-708.39641853226408)); |
127 EXPECT_EQ(3.307553003638408e-308, exp(-708.0)); | 139 EXPECT_EQ(3.307553003638408e-308, exp(-708.0)); |
128 EXPECT_EQ(4.9406564584124654e-324, exp(-7.45133219101941108420e+02)); | 140 EXPECT_EQ(4.9406564584124654e-324, exp(-7.45133219101941108420e+02)); |
129 EXPECT_EQ(0.36787944117144233, exp(-1.0)); | 141 EXPECT_EQ(0.36787944117144233, exp(-1.0)); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 EXPECT_EQ(0.7071067811865474, sin(9.0 / 4.0 * kPI)); | 286 EXPECT_EQ(0.7071067811865474, sin(9.0 / 4.0 * kPI)); |
275 EXPECT_EQ(0.7071067811865483, sin(11.0 / 4.0 * kPI)); | 287 EXPECT_EQ(0.7071067811865483, sin(11.0 / 4.0 * kPI)); |
276 EXPECT_EQ(-0.7071067811865479, sin(13.0 / 4.0 * kPI)); | 288 EXPECT_EQ(-0.7071067811865479, sin(13.0 / 4.0 * kPI)); |
277 EXPECT_EQ(-3.2103381051568376e-11, sin(1048576.0 / 4 * kPI)); | 289 EXPECT_EQ(-3.2103381051568376e-11, sin(1048576.0 / 4 * kPI)); |
278 | 290 |
279 // Test Hayne-Panek reduction. | 291 // Test Hayne-Panek reduction. |
280 EXPECT_EQ(0.377820109360752e0, sin(kTwo120)); | 292 EXPECT_EQ(0.377820109360752e0, sin(kTwo120)); |
281 EXPECT_EQ(-0.377820109360752e0, sin(-kTwo120)); | 293 EXPECT_EQ(-0.377820109360752e0, sin(-kTwo120)); |
282 } | 294 } |
283 | 295 |
| 296 TEST(Ieee754, Sinh) { |
| 297 // Test values mentioned in the EcmaScript spec. |
| 298 EXPECT_THAT(sinh(std::numeric_limits<double>::quiet_NaN()), IsNaN()); |
| 299 EXPECT_THAT(sinh(std::numeric_limits<double>::signaling_NaN()), IsNaN()); |
| 300 EXPECT_THAT(sinh(std::numeric_limits<double>::infinity()), |
| 301 std::numeric_limits<double>::infinity()); |
| 302 EXPECT_THAT(sinh(-std::numeric_limits<double>::infinity()), |
| 303 -std::numeric_limits<double>::infinity()); |
| 304 EXPECT_EQ(0.0, sinh(0.0)); |
| 305 EXPECT_EQ(-0.0, sinh(-0.0)); |
| 306 } |
| 307 |
284 TEST(Ieee754, Tan) { | 308 TEST(Ieee754, Tan) { |
285 // Test values mentioned in the EcmaScript spec. | 309 // Test values mentioned in the EcmaScript spec. |
286 EXPECT_THAT(tan(std::numeric_limits<double>::quiet_NaN()), IsNaN()); | 310 EXPECT_THAT(tan(std::numeric_limits<double>::quiet_NaN()), IsNaN()); |
287 EXPECT_THAT(tan(std::numeric_limits<double>::signaling_NaN()), IsNaN()); | 311 EXPECT_THAT(tan(std::numeric_limits<double>::signaling_NaN()), IsNaN()); |
288 EXPECT_THAT(tan(std::numeric_limits<double>::infinity()), IsNaN()); | 312 EXPECT_THAT(tan(std::numeric_limits<double>::infinity()), IsNaN()); |
289 EXPECT_THAT(tan(-std::numeric_limits<double>::infinity()), IsNaN()); | 313 EXPECT_THAT(tan(-std::numeric_limits<double>::infinity()), IsNaN()); |
290 | 314 |
291 // Tests for tan for |x| < pi/4 | 315 // Tests for tan for |x| < pi/4 |
292 EXPECT_EQ(std::numeric_limits<double>::infinity(), 1 / tan(0.0)); | 316 EXPECT_EQ(std::numeric_limits<double>::infinity(), 1 / tan(0.0)); |
293 EXPECT_EQ(-std::numeric_limits<double>::infinity(), 1 / tan(-0.0)); | 317 EXPECT_EQ(-std::numeric_limits<double>::infinity(), 1 / tan(-0.0)); |
(...skipping 17 matching lines...) Expand all Loading... |
311 EXPECT_EQ(-1.0000000000000004, tan(7.0 / 4.0 * kPI)); | 335 EXPECT_EQ(-1.0000000000000004, tan(7.0 / 4.0 * kPI)); |
312 EXPECT_EQ(0.9999999999999994, tan(9.0 / 4.0 * kPI)); | 336 EXPECT_EQ(0.9999999999999994, tan(9.0 / 4.0 * kPI)); |
313 EXPECT_EQ(-6.420676210313675e-11, tan(1048576.0 / 2.0 * kPI)); | 337 EXPECT_EQ(-6.420676210313675e-11, tan(1048576.0 / 2.0 * kPI)); |
314 EXPECT_EQ(2.910566692924059e11, tan(1048575.0 / 2.0 * kPI)); | 338 EXPECT_EQ(2.910566692924059e11, tan(1048575.0 / 2.0 * kPI)); |
315 | 339 |
316 // Test Hayne-Panek reduction. | 340 // Test Hayne-Panek reduction. |
317 EXPECT_EQ(-0.40806638884180424e0, tan(kTwo120)); | 341 EXPECT_EQ(-0.40806638884180424e0, tan(kTwo120)); |
318 EXPECT_EQ(0.40806638884180424e0, tan(-kTwo120)); | 342 EXPECT_EQ(0.40806638884180424e0, tan(-kTwo120)); |
319 } | 343 } |
320 | 344 |
| 345 TEST(Ieee754, Tanh) { |
| 346 // Test values mentioned in the EcmaScript spec. |
| 347 EXPECT_THAT(tanh(std::numeric_limits<double>::quiet_NaN()), IsNaN()); |
| 348 EXPECT_THAT(tanh(std::numeric_limits<double>::signaling_NaN()), IsNaN()); |
| 349 EXPECT_THAT(tanh(std::numeric_limits<double>::infinity()), 1); |
| 350 EXPECT_THAT(tanh(-std::numeric_limits<double>::infinity()), -1); |
| 351 EXPECT_EQ(0.0, tanh(0.0)); |
| 352 EXPECT_EQ(-0.0, tanh(-0.0)); |
| 353 } |
| 354 |
321 } // namespace ieee754 | 355 } // namespace ieee754 |
322 } // namespace base | 356 } // namespace base |
323 } // namespace v8 | 357 } // namespace v8 |
OLD | NEW |