Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: test/unittests/base/ieee754-unittest.cc

Issue 2083453002: [builtins] Introduce proper Float64Tan operator. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 {
20
21 double const kPI = 3.141592653589793;
22 double const kTwo120 = 1.329227995784916e+36;
23
24 } // namespace
25
19 TEST(Ieee754, Atan) { 26 TEST(Ieee754, Atan) {
20 EXPECT_THAT(atan(std::numeric_limits<double>::quiet_NaN()), IsNaN()); 27 EXPECT_THAT(atan(std::numeric_limits<double>::quiet_NaN()), IsNaN());
21 EXPECT_THAT(atan(std::numeric_limits<double>::signaling_NaN()), IsNaN()); 28 EXPECT_THAT(atan(std::numeric_limits<double>::signaling_NaN()), IsNaN());
22 EXPECT_THAT(atan(-0.0), BitEq(-0.0)); 29 EXPECT_THAT(atan(-0.0), BitEq(-0.0));
23 EXPECT_THAT(atan(0.0), BitEq(0.0)); 30 EXPECT_THAT(atan(0.0), BitEq(0.0));
24 EXPECT_DOUBLE_EQ(1.5707963267948966, 31 EXPECT_DOUBLE_EQ(1.5707963267948966,
25 atan(std::numeric_limits<double>::infinity())); 32 atan(std::numeric_limits<double>::infinity()));
26 EXPECT_DOUBLE_EQ(-1.5707963267948966, 33 EXPECT_DOUBLE_EQ(-1.5707963267948966,
27 atan(-std::numeric_limits<double>::infinity())); 34 atan(-std::numeric_limits<double>::infinity()));
28 } 35 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 97
91 // Tests for cos. 98 // Tests for cos.
92 EXPECT_EQ(1, cos(3.725290298461914e-9)); 99 EXPECT_EQ(1, cos(3.725290298461914e-9));
93 // Cover different code paths in KERNELCOS. 100 // Cover different code paths in KERNELCOS.
94 EXPECT_EQ(0.9689124217106447, cos(0.25)); 101 EXPECT_EQ(0.9689124217106447, cos(0.25));
95 EXPECT_EQ(0.8775825618903728, cos(0.5)); 102 EXPECT_EQ(0.8775825618903728, cos(0.5));
96 EXPECT_EQ(0.7073882691671998, cos(0.785)); 103 EXPECT_EQ(0.7073882691671998, cos(0.785));
97 // Test that cos(Math.PI/2) != 0 since Math.PI is not exact. 104 // Test that cos(Math.PI/2) != 0 since Math.PI is not exact.
98 EXPECT_EQ(6.123233995736766e-17, cos(1.5707963267948966)); 105 EXPECT_EQ(6.123233995736766e-17, cos(1.5707963267948966));
99 // Test cos for various phases. 106 // Test cos for various phases.
100 EXPECT_EQ(0.7071067811865474, cos(7.0 / 4 * 3.141592653589793)); 107 EXPECT_EQ(0.7071067811865474, cos(7.0 / 4 * kPI));
101 EXPECT_EQ(0.7071067811865477, cos(9.0 / 4 * 3.141592653589793)); 108 EXPECT_EQ(0.7071067811865477, cos(9.0 / 4 * kPI));
102 EXPECT_EQ(-0.7071067811865467, cos(11.0 / 4 * 3.141592653589793)); 109 EXPECT_EQ(-0.7071067811865467, cos(11.0 / 4 * kPI));
103 EXPECT_EQ(-0.7071067811865471, cos(13.0 / 4 * 3.141592653589793)); 110 EXPECT_EQ(-0.7071067811865471, cos(13.0 / 4 * kPI));
104 EXPECT_EQ(0.9367521275331447, cos(1000000.0)); 111 EXPECT_EQ(0.9367521275331447, cos(1000000.0));
105 EXPECT_EQ(-3.435757038074824e-12, cos(1048575.0 / 2 * 3.141592653589793)); 112 EXPECT_EQ(-3.435757038074824e-12, cos(1048575.0 / 2 * kPI));
113
114 // Test Hayne-Panek reduction.
115 EXPECT_EQ(-0.9258790228548379e0, cos(kTwo120));
116 EXPECT_EQ(-0.9258790228548379e0, cos(-kTwo120));
106 } 117 }
107 118
108 TEST(Ieee754, Exp) { 119 TEST(Ieee754, Exp) {
109 EXPECT_THAT(exp(std::numeric_limits<double>::quiet_NaN()), IsNaN()); 120 EXPECT_THAT(exp(std::numeric_limits<double>::quiet_NaN()), IsNaN());
110 EXPECT_THAT(exp(std::numeric_limits<double>::signaling_NaN()), IsNaN()); 121 EXPECT_THAT(exp(std::numeric_limits<double>::signaling_NaN()), IsNaN());
111 EXPECT_EQ(0.0, exp(-std::numeric_limits<double>::infinity())); 122 EXPECT_EQ(0.0, exp(-std::numeric_limits<double>::infinity()));
112 EXPECT_EQ(0.0, exp(-1000)); 123 EXPECT_EQ(0.0, exp(-1000));
113 EXPECT_EQ(0.0, exp(-745.1332191019412)); 124 EXPECT_EQ(0.0, exp(-745.1332191019412));
114 EXPECT_EQ(2.2250738585072626e-308, exp(-708.39641853226408)); 125 EXPECT_EQ(2.2250738585072626e-308, exp(-708.39641853226408));
115 EXPECT_EQ(3.307553003638408e-308, exp(-708.0)); 126 EXPECT_EQ(3.307553003638408e-308, exp(-708.0));
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // sin(x) = x for x < 2^-27 248 // sin(x) = x for x < 2^-27
238 EXPECT_EQ(2.3283064365386963e-10, sin(2.3283064365386963e-10)); 249 EXPECT_EQ(2.3283064365386963e-10, sin(2.3283064365386963e-10));
239 EXPECT_EQ(-2.3283064365386963e-10, sin(-2.3283064365386963e-10)); 250 EXPECT_EQ(-2.3283064365386963e-10, sin(-2.3283064365386963e-10));
240 // sin(pi/8) = sqrt(sqrt(2)-1)/2^(3/4) 251 // sin(pi/8) = sqrt(sqrt(2)-1)/2^(3/4)
241 EXPECT_EQ(0.3826834323650898, sin(0.39269908169872414)); 252 EXPECT_EQ(0.3826834323650898, sin(0.39269908169872414));
242 EXPECT_EQ(-0.3826834323650898, sin(-0.39269908169872414)); 253 EXPECT_EQ(-0.3826834323650898, sin(-0.39269908169872414));
243 254
244 // Tests for sin. 255 // Tests for sin.
245 EXPECT_EQ(0.479425538604203, sin(0.5)); 256 EXPECT_EQ(0.479425538604203, sin(0.5));
246 EXPECT_EQ(-0.479425538604203, sin(-0.5)); 257 EXPECT_EQ(-0.479425538604203, sin(-0.5));
247 EXPECT_EQ(1, sin(1.5707963267948966)); 258 EXPECT_EQ(1, sin(kPI / 2.0));
248 EXPECT_EQ(-1, sin(-1.5707963267948966)); 259 EXPECT_EQ(-1, sin(-kPI / 2.0));
249 // Test that sin(Math.PI) != 0 since Math.PI is not exact. 260 // Test that sin(Math.PI) != 0 since Math.PI is not exact.
250 EXPECT_EQ(1.2246467991473532e-16, sin(3.141592653589793)); 261 EXPECT_EQ(1.2246467991473532e-16, sin(kPI));
251 EXPECT_EQ(-7.047032979958965e-14, sin(2200 * 3.141592653589793)); 262 EXPECT_EQ(-7.047032979958965e-14, sin(2200.0 * kPI));
252 // Test sin for various phases. 263 // Test sin for various phases.
253 EXPECT_EQ(-0.7071067811865477, sin(7.0 / 4 * 3.141592653589793)); 264 EXPECT_EQ(-0.7071067811865477, sin(7.0 / 4.0 * kPI));
254 EXPECT_EQ(0.7071067811865474, sin(9.0 / 4 * 3.141592653589793)); 265 EXPECT_EQ(0.7071067811865474, sin(9.0 / 4.0 * kPI));
255 EXPECT_EQ(0.7071067811865483, sin(11.0 / 4 * 3.141592653589793)); 266 EXPECT_EQ(0.7071067811865483, sin(11.0 / 4.0 * kPI));
256 EXPECT_EQ(-0.7071067811865479, sin(13.0 / 4 * 3.141592653589793)); 267 EXPECT_EQ(-0.7071067811865479, sin(13.0 / 4.0 * kPI));
257 EXPECT_EQ(-3.2103381051568376e-11, sin(1048576.0 / 4 * 3.141592653589793)); 268 EXPECT_EQ(-3.2103381051568376e-11, sin(1048576.0 / 4 * kPI));
269
270 // Test Hayne-Panek reduction.
271 EXPECT_EQ(0.377820109360752e0, sin(kTwo120));
272 EXPECT_EQ(-0.377820109360752e0, sin(-kTwo120));
273 }
274
275 TEST(Ieee754, Tan) {
276 // Test values mentioned in the EcmaScript spec.
277 EXPECT_THAT(tan(std::numeric_limits<double>::quiet_NaN()), IsNaN());
278 EXPECT_THAT(tan(std::numeric_limits<double>::signaling_NaN()), IsNaN());
279 EXPECT_THAT(tan(std::numeric_limits<double>::infinity()), IsNaN());
280 EXPECT_THAT(tan(-std::numeric_limits<double>::infinity()), IsNaN());
281
282 // Tests for tan for |x| < pi/4
283 EXPECT_EQ(std::numeric_limits<double>::infinity(), 1 / tan(0.0));
284 EXPECT_EQ(-std::numeric_limits<double>::infinity(), 1 / tan(-0.0));
285 // tan(x) = x for |x| < 2^-28
286 EXPECT_EQ(2.3283064365386963e-10, tan(2.3283064365386963e-10));
287 EXPECT_EQ(-2.3283064365386963e-10, tan(-2.3283064365386963e-10));
288 // Test KERNELTAN for |x| > 0.67434.
289 EXPECT_EQ(0.8211418015898941, tan(11.0 / 16.0));
290 EXPECT_EQ(-0.8211418015898941, tan(-11.0 / 16.0));
291 EXPECT_EQ(0.41421356237309503, tan(0.39269908169872414));
292 // crbug/427468
293 EXPECT_EQ(0.7993357819992383, tan(0.6743358));
294
295 // Tests for tan.
296 EXPECT_EQ(3.725290298461914e-9, tan(3.725290298461914e-9));
297 // Test that tan(PI/2) != Infinity since PI is not exact.
298 EXPECT_EQ(1.633123935319537e16, tan(kPI / 2));
299 // Cover different code paths in KERNELTAN (tangent and cotangent)
300 EXPECT_EQ(0.5463024898437905, tan(0.5));
301 EXPECT_EQ(2.0000000000000027, tan(1.107148717794091));
302 EXPECT_EQ(-1.0000000000000004, tan(7.0 / 4.0 * kPI));
303 EXPECT_EQ(0.9999999999999994, tan(9.0 / 4.0 * kPI));
304 EXPECT_EQ(-6.420676210313675e-11, tan(1048576.0 / 2.0 * kPI));
305 EXPECT_EQ(2.910566692924059e11, tan(1048575.0 / 2.0 * kPI));
306
307 // Test Hayne-Panek reduction.
308 EXPECT_EQ(-0.40806638884180424e0, tan(kTwo120));
309 EXPECT_EQ(0.40806638884180424e0, tan(-kTwo120));
258 } 310 }
259 311
260 } // namespace ieee754 312 } // namespace ieee754
261 } // namespace base 313 } // namespace base
262 } // namespace v8 314 } // namespace v8
OLDNEW
« no previous file with comments | « test/mjsunit/es6/math-log2-log10.js ('k') | test/unittests/compiler/js-builtin-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698