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

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: fix comment 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
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 // Flags: --no-fast-math
29
28 [Math.sinh, Math.cosh, Math.tanh, Math.asinh, Math.acosh, Math.atanh]. 30 [Math.sinh, Math.cosh, Math.tanh, Math.asinh, Math.acosh, Math.atanh].
29 forEach(function(fun) { 31 forEach(function(fun) {
30 assertTrue(isNaN(fun(NaN))); 32 assertTrue(isNaN(fun(NaN)));
31 assertTrue(isNaN(fun("abc"))); 33 assertTrue(isNaN(fun("abc")));
32 assertTrue(isNaN(fun({}))); 34 assertTrue(isNaN(fun({})));
33 assertEquals(fun(0), fun([])); 35 assertEquals(fun(0), fun([]));
34 assertTrue(isNaN(fun([1, 1]))); 36 assertTrue(isNaN(fun([1, 1])));
35 assertEquals(fun(1.11), fun({ toString: function() { return "1.11"; } })); 37 assertEquals(fun(1.11), fun({ toString: function() { return "1.11"; } }));
36 assertEquals(fun(-3.1), fun({ toString: function() { return -3.1; } })); 38 assertEquals(fun(-3.1), fun({ toString: function() { return -3.1; } }));
37 assertEquals(fun(-1.1), fun({ valueOf: function() { return "-1.1"; } })); 39 assertEquals(fun(-1.1), fun({ valueOf: function() { return "-1.1"; } }));
(...skipping 21 matching lines...) Expand all
59 61
60 62
61 [Math.sinh, Math.asinh].forEach(function(fun) { 63 [Math.sinh, Math.asinh].forEach(function(fun) {
62 assertEquals("-Infinity", String(fun(-Infinity))); 64 assertEquals("-Infinity", String(fun(-Infinity)));
63 assertEquals("Infinity", String(fun(Infinity))); 65 assertEquals("Infinity", String(fun(Infinity)));
64 assertEquals("-Infinity", String(fun("-Infinity"))); 66 assertEquals("-Infinity", String(fun("-Infinity")));
65 assertEquals("Infinity", String(fun("Infinity"))); 67 assertEquals("Infinity", String(fun("Infinity")));
66 }); 68 });
67 69
68 70
69 assertEquals("Infinity", String(Math.cosh(-Infinity))); 71 assertEquals(Infinity, Math.cosh(-Infinity));
70 assertEquals("Infinity", String(Math.cosh(Infinity))); 72 assertEquals(Infinity, Math.cosh(Infinity));
71 assertEquals("Infinity", String(Math.cosh("-Infinity"))); 73 assertEquals(Infinity, Math.cosh("-Infinity"));
72 assertEquals("Infinity", String(Math.cosh("Infinity"))); 74 assertEquals(Infinity, Math.cosh("Infinity"));
73 75
74 76
75 assertEquals("-Infinity", String(Math.atanh(-1))); 77 assertEquals(-Infinity, Math.atanh(-1));
76 assertEquals("Infinity", String(Math.atanh(1))); 78 assertEquals(Infinity, Math.atanh(1));
77 79
78 // Math.atanh(x) is NaN for |x| > 1 and NaN 80 // Math.atanh(x) is NaN for |x| > 1 and NaN
79 [1.000000000001, Math.PI, 10000000, 2, Infinity, NaN].forEach(function(x) { 81 [1.000000000001, Math.PI, 10000000, 2, Infinity, NaN].forEach(function(x) {
80 assertTrue(isNaN(Math.atanh(-x))); 82 assertTrue(isNaN(Math.atanh(-x)));
81 assertTrue(isNaN(Math.atanh(x))); 83 assertTrue(isNaN(Math.atanh(x)));
82 }); 84 });
83 85
84 86
87 assertEquals(0, Math.sinh(0));
88 assertEquals(-Infinity, 1/Math.sinh(-0));
85 assertEquals(1, Math.tanh(Infinity)); 89 assertEquals(1, Math.tanh(Infinity));
86 assertEquals(-1, Math.tanh(-Infinity)); 90 assertEquals(-1, Math.tanh(-Infinity));
87 assertEquals(1, Math.cosh(0)); 91 assertEquals(1, Math.cosh(0));
88 assertEquals(1, Math.cosh(-0)); 92 assertEquals(1, Math.cosh(-0));
89 93
90 assertEquals(0, Math.acosh(1)); 94 assertEquals(0, Math.acosh(1));
91 assertEquals("Infinity", String(Math.acosh(Infinity))); 95 assertEquals("Infinity", String(Math.acosh(Infinity)));
92 96
93 // Math.acosh(x) is NaN for x < 1 97 // Math.acosh(x) is NaN for x < 1
94 [0.99999999999, 0.2, -1000, 0, -0].forEach(function(x) { 98 [0.99999999999, 0.2, -1000, 0, -0].forEach(function(x) {
95 assertTrue(isNaN(Math.acosh(x))); 99 assertTrue(isNaN(Math.acosh(x)));
96 }); 100 });
97 101
98 102
99 // Some random samples. 103 // Some random samples.
100 assertEqualsDelta(0.5210953054937, Math.sinh(0.5), 1E-12);
101 assertEqualsDelta(74.203210577788, Math.sinh(5), 1E-12); 104 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); 105 assertEqualsDelta(-74.203210577788, Math.sinh(-5), 1E-12);
Raymond Toy 2014/08/28 17:15:55 Are these two sinh tests needed now? Perhaps you
104 106
105 assertEqualsDelta(1.1276259652063, Math.cosh(0.5), 1E-12); 107 assertEqualsDelta(1.1276259652063, Math.cosh(0.5), 1E-12);
106 assertEqualsDelta(74.209948524787, Math.cosh(5), 1E-12); 108 assertEqualsDelta(74.209948524787, Math.cosh(5), 1E-12);
107 assertEqualsDelta(1.1276259652063, Math.cosh(-0.5), 1E-12); 109 assertEqualsDelta(1.1276259652063, Math.cosh(-0.5), 1E-12);
108 assertEqualsDelta(74.209948524787, Math.cosh(-5), 1E-12); 110 assertEqualsDelta(74.209948524787, Math.cosh(-5), 1E-12);
109 111
110 assertEqualsDelta(0.4621171572600, Math.tanh(0.5), 1E-12); 112 assertEqualsDelta(0.4621171572600, Math.tanh(0.5), 1E-12);
111 assertEqualsDelta(0.9999092042625, Math.tanh(5), 1E-12); 113 assertEqualsDelta(0.9999092042625, Math.tanh(5), 1E-12);
112 assertEqualsDelta(-0.4621171572600, Math.tanh(-0.5), 1E-12); 114 assertEqualsDelta(-0.4621171572600, Math.tanh(-0.5), 1E-12);
113 assertEqualsDelta(-0.9999092042625, Math.tanh(-5), 1E-12); 115 assertEqualsDelta(-0.9999092042625, Math.tanh(-5), 1E-12);
(...skipping 13 matching lines...) Expand all
127 assertEqualsDelta(-0.5493061443341, Math.atanh(-0.5), 1E-12); 129 assertEqualsDelta(-0.5493061443341, Math.atanh(-0.5), 1E-12);
128 assertEqualsDelta(-0.1003353477311, Math.atanh(-0.1), 1E-12); 130 assertEqualsDelta(-0.1003353477311, Math.atanh(-0.1), 1E-12);
129 131
130 [0, 1E-50, 1E-10, 1E10, 1E50, 1E100, 1E150].forEach(function(x) { 132 [0, 1E-50, 1E-10, 1E10, 1E50, 1E100, 1E150].forEach(function(x) {
131 assertEqualsDelta(Math.asinh(x), -Math.asinh(-x), 1E-12); 133 assertEqualsDelta(Math.asinh(x), -Math.asinh(-x), 1E-12);
132 }); 134 });
133 135
134 [1-(1E-16), 0, 1E-10, 1E-50].forEach(function(x) { 136 [1-(1E-16), 0, 1E-10, 1E-50].forEach(function(x) {
135 assertEqualsDelta(Math.atanh(x), -Math.atanh(-x), 1E-12); 137 assertEqualsDelta(Math.atanh(x), -Math.atanh(-x), 1E-12);
136 }); 138 });
139
140
141 // Implementation-specific tests for sinh.
142 // Case |x| < 2^-28
143 assertEquals(Math.pow(2, -29), Math.sinh(Math.pow(2, -29)));
144 assertEquals(-Math.pow(2, -29), Math.sinh(-Math.pow(2, -29)));
145 // Case |x| < 1
146 assertEquals(0.5210953054937474, Math.sinh(0.5));
147 assertEquals(-0.5210953054937474, Math.sinh(-0.5));
148 // sinh(10*log(2)) = 1048575/2048, case |x| < 22
149 assertEquals(1048575/2048, Math.sinh(10*Math.LN2));
150 assertEquals(-1048575/2048, Math.sinh(-10*Math.LN2));
151 // Case |x| < 22
152 assertEquals(11013.232874703393, Math.sinh(10));
153 assertEquals(-11013.232874703393, Math.sinh(-10));
154 // Case |x| in [22, log(maxdouble)]
155 assertEquals(2.1474836479999983e9, Math.sinh(32*Math.LN2));
156 assertEquals(-2.1474836479999983e9, Math.sinh(-32*Math.LN2));
157 // Case |x| in [22, log(maxdouble)]
158 assertEquals(1.3440585709080678e43, Math.sinh(100));
159 assertEquals(-1.3440585709080678e43, Math.sinh(-100));
160 // No overflow, case |x| in [log(maxdouble), threshold]
161 assertEquals(1.7976931348621744e308, Math.sinh(710.4758600739439));
162 assertEquals(-1.7976931348621744e308, Math.sinh(-710.4758600739439));
Raymond Toy 2014/08/27 16:22:02 Do the tests in lines 155-162 actually pass? They
Yang 2014/08/28 07:18:08 They do, with --no-fast-math we use the slow libra
Raymond Toy 2014/08/28 17:15:55 If this is how you normally run these tests, then
163 // Overflow, case |x| > threshold
164 assertEquals(Infinity, Math.sinh(710.475860073944));
165 assertEquals(-Infinity, Math.sinh(-710.475860073944));
166 assertEquals(Infinity, Math.sinh(1000));
167 assertEquals(-Infinity, Math.sinh(-1000));
OLDNEW
« no previous file with comments | « src/math.js ('k') | third_party/fdlibm/fdlibm.h » ('j') | third_party/fdlibm/fdlibm.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698