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

Side by Side Diff: test/mjsunit/es6/math-hyperbolic.js

Issue 488003005: Port fdlibm implementation for Math.sinh. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: added TODO Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « src/math.js ('k') | third_party/fdlibm/fdlibm.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // TODO(3468): we rely on a precise Math.exp.
29 // Flags: --no-fast-math
30
28 [Math.sinh, Math.cosh, Math.tanh, Math.asinh, Math.acosh, Math.atanh]. 31 [Math.sinh, Math.cosh, Math.tanh, Math.asinh, Math.acosh, Math.atanh].
29 forEach(function(fun) { 32 forEach(function(fun) {
30 assertTrue(isNaN(fun(NaN))); 33 assertTrue(isNaN(fun(NaN)));
31 assertTrue(isNaN(fun("abc"))); 34 assertTrue(isNaN(fun("abc")));
32 assertTrue(isNaN(fun({}))); 35 assertTrue(isNaN(fun({})));
33 assertEquals(fun(0), fun([])); 36 assertEquals(fun(0), fun([]));
34 assertTrue(isNaN(fun([1, 1]))); 37 assertTrue(isNaN(fun([1, 1])));
35 assertEquals(fun(1.11), fun({ toString: function() { return "1.11"; } })); 38 assertEquals(fun(1.11), fun({ toString: function() { return "1.11"; } }));
36 assertEquals(fun(-3.1), fun({ toString: function() { return -3.1; } })); 39 assertEquals(fun(-3.1), fun({ toString: function() { return -3.1; } }));
37 assertEquals(fun(-1.1), fun({ valueOf: function() { return "-1.1"; } })); 40 assertEquals(fun(-1.1), fun({ valueOf: function() { return "-1.1"; } }));
(...skipping 21 matching lines...) Expand all
59 62
60 63
61 [Math.sinh, Math.asinh].forEach(function(fun) { 64 [Math.sinh, Math.asinh].forEach(function(fun) {
62 assertEquals("-Infinity", String(fun(-Infinity))); 65 assertEquals("-Infinity", String(fun(-Infinity)));
63 assertEquals("Infinity", String(fun(Infinity))); 66 assertEquals("Infinity", String(fun(Infinity)));
64 assertEquals("-Infinity", String(fun("-Infinity"))); 67 assertEquals("-Infinity", String(fun("-Infinity")));
65 assertEquals("Infinity", String(fun("Infinity"))); 68 assertEquals("Infinity", String(fun("Infinity")));
66 }); 69 });
67 70
68 71
69 assertEquals("Infinity", String(Math.cosh(-Infinity))); 72 assertEquals(Infinity, Math.cosh(-Infinity));
70 assertEquals("Infinity", String(Math.cosh(Infinity))); 73 assertEquals(Infinity, Math.cosh(Infinity));
71 assertEquals("Infinity", String(Math.cosh("-Infinity"))); 74 assertEquals(Infinity, Math.cosh("-Infinity"));
72 assertEquals("Infinity", String(Math.cosh("Infinity"))); 75 assertEquals(Infinity, Math.cosh("Infinity"));
73 76
74 77
75 assertEquals("-Infinity", String(Math.atanh(-1))); 78 assertEquals(-Infinity, Math.atanh(-1));
76 assertEquals("Infinity", String(Math.atanh(1))); 79 assertEquals(Infinity, Math.atanh(1));
77 80
78 // Math.atanh(x) is NaN for |x| > 1 and NaN 81 // Math.atanh(x) is NaN for |x| > 1 and NaN
79 [1.000000000001, Math.PI, 10000000, 2, Infinity, NaN].forEach(function(x) { 82 [1.000000000001, Math.PI, 10000000, 2, Infinity, NaN].forEach(function(x) {
80 assertTrue(isNaN(Math.atanh(-x))); 83 assertTrue(isNaN(Math.atanh(-x)));
81 assertTrue(isNaN(Math.atanh(x))); 84 assertTrue(isNaN(Math.atanh(x)));
82 }); 85 });
83 86
84 87
88 assertEquals(0, Math.sinh(0));
89 assertEquals(-Infinity, 1/Math.sinh(-0));
85 assertEquals(1, Math.tanh(Infinity)); 90 assertEquals(1, Math.tanh(Infinity));
86 assertEquals(-1, Math.tanh(-Infinity)); 91 assertEquals(-1, Math.tanh(-Infinity));
87 assertEquals(1, Math.cosh(0)); 92 assertEquals(1, Math.cosh(0));
88 assertEquals(1, Math.cosh(-0)); 93 assertEquals(1, Math.cosh(-0));
89 94
90 assertEquals(0, Math.acosh(1)); 95 assertEquals(0, Math.acosh(1));
91 assertEquals("Infinity", String(Math.acosh(Infinity))); 96 assertEquals("Infinity", String(Math.acosh(Infinity)));
92 97
93 // Math.acosh(x) is NaN for x < 1 98 // Math.acosh(x) is NaN for x < 1
94 [0.99999999999, 0.2, -1000, 0, -0].forEach(function(x) { 99 [0.99999999999, 0.2, -1000, 0, -0].forEach(function(x) {
95 assertTrue(isNaN(Math.acosh(x))); 100 assertTrue(isNaN(Math.acosh(x)));
96 }); 101 });
97 102
98 103
99 // Some random samples. 104 // Some random samples.
100 assertEqualsDelta(0.5210953054937, Math.sinh(0.5), 1E-12);
101 assertEqualsDelta(74.203210577788, Math.sinh(5), 1E-12); 105 assertEqualsDelta(74.203210577788, Math.sinh(5), 1E-12);
102 assertEqualsDelta(-0.5210953054937, Math.sinh(-0.5), 1E-12);
103 assertEqualsDelta(-74.203210577788, Math.sinh(-5), 1E-12); 106 assertEqualsDelta(-74.203210577788, Math.sinh(-5), 1E-12);
104 107
105 assertEqualsDelta(1.1276259652063, Math.cosh(0.5), 1E-12); 108 assertEqualsDelta(1.1276259652063, Math.cosh(0.5), 1E-12);
106 assertEqualsDelta(74.209948524787, Math.cosh(5), 1E-12); 109 assertEqualsDelta(74.209948524787, Math.cosh(5), 1E-12);
107 assertEqualsDelta(1.1276259652063, Math.cosh(-0.5), 1E-12); 110 assertEqualsDelta(1.1276259652063, Math.cosh(-0.5), 1E-12);
108 assertEqualsDelta(74.209948524787, Math.cosh(-5), 1E-12); 111 assertEqualsDelta(74.209948524787, Math.cosh(-5), 1E-12);
109 112
110 assertEqualsDelta(0.4621171572600, Math.tanh(0.5), 1E-12); 113 assertEqualsDelta(0.4621171572600, Math.tanh(0.5), 1E-12);
111 assertEqualsDelta(0.9999092042625, Math.tanh(5), 1E-12); 114 assertEqualsDelta(0.9999092042625, Math.tanh(5), 1E-12);
112 assertEqualsDelta(-0.4621171572600, Math.tanh(-0.5), 1E-12); 115 assertEqualsDelta(-0.4621171572600, Math.tanh(-0.5), 1E-12);
(...skipping 14 matching lines...) Expand all
127 assertEqualsDelta(-0.5493061443341, Math.atanh(-0.5), 1E-12); 130 assertEqualsDelta(-0.5493061443341, Math.atanh(-0.5), 1E-12);
128 assertEqualsDelta(-0.1003353477311, Math.atanh(-0.1), 1E-12); 131 assertEqualsDelta(-0.1003353477311, Math.atanh(-0.1), 1E-12);
129 132
130 [0, 1E-50, 1E-10, 1E10, 1E50, 1E100, 1E150].forEach(function(x) { 133 [0, 1E-50, 1E-10, 1E10, 1E50, 1E100, 1E150].forEach(function(x) {
131 assertEqualsDelta(Math.asinh(x), -Math.asinh(-x), 1E-12); 134 assertEqualsDelta(Math.asinh(x), -Math.asinh(-x), 1E-12);
132 }); 135 });
133 136
134 [1-(1E-16), 0, 1E-10, 1E-50].forEach(function(x) { 137 [1-(1E-16), 0, 1E-10, 1E-50].forEach(function(x) {
135 assertEqualsDelta(Math.atanh(x), -Math.atanh(-x), 1E-12); 138 assertEqualsDelta(Math.atanh(x), -Math.atanh(-x), 1E-12);
136 }); 139 });
140
141
142 // Implementation-specific tests for sinh.
143 // Case |x| < 2^-28
144 assertEquals(Math.pow(2, -29), Math.sinh(Math.pow(2, -29)));
145 assertEquals(-Math.pow(2, -29), Math.sinh(-Math.pow(2, -29)));
146 // Case |x| < 1
147 assertEquals(0.5210953054937474, Math.sinh(0.5));
148 assertEquals(-0.5210953054937474, Math.sinh(-0.5));
149 // sinh(10*log(2)) = 1048575/2048, case |x| < 22
150 assertEquals(1048575/2048, Math.sinh(10*Math.LN2));
151 assertEquals(-1048575/2048, Math.sinh(-10*Math.LN2));
152 // Case |x| < 22
153 assertEquals(11013.232874703393, Math.sinh(10));
154 assertEquals(-11013.232874703393, Math.sinh(-10));
155 // Case |x| in [22, log(maxdouble)]
156 assertEquals(2.1474836479999983e9, Math.sinh(32*Math.LN2));
157 assertEquals(-2.1474836479999983e9, Math.sinh(-32*Math.LN2));
158 // Case |x| in [22, log(maxdouble)]
159 assertEquals(1.3440585709080678e43, Math.sinh(100));
160 assertEquals(-1.3440585709080678e43, Math.sinh(-100));
161 // No overflow, case |x| in [log(maxdouble), threshold]
162 assertEquals(1.7976931348621744e308, Math.sinh(710.4758600739439));
163 assertEquals(-1.7976931348621744e308, Math.sinh(-710.4758600739439));
164 // Overflow, case |x| > threshold
165 assertEquals(Infinity, Math.sinh(710.475860073944));
166 assertEquals(-Infinity, Math.sinh(-710.475860073944));
167 assertEquals(Infinity, Math.sinh(1000));
168 assertEquals(-Infinity, Math.sinh(-1000));
OLDNEW
« no previous file with comments | « src/math.js ('k') | third_party/fdlibm/fdlibm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698