]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/math-pow-basics.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / math-pow-basics.js
1 function valuesAreClose(a, b) {
2 return Math.abs(a / b) - 1 < 1e-10;
3 }
4
5 // Some random values.
6 function mathPowDoubleDouble1(x, y) {
7 return Math.pow(x, y)
8 }
9 noInline(mathPowDoubleDouble1);
10
11 function mathPowDoubleInt1(x, y) {
12 return Math.pow(x, y)
13 }
14 noInline(mathPowDoubleInt1);
15
16 function test1(x, y, expected1, expected2) {
17 for (var i = 0; i < 10000; ++i) {
18 var result = mathPowDoubleDouble1(x, y);
19 if (!valuesAreClose(result, expected1))
20 throw "Error: bad result, mathPowDoubleDouble1(" + x + ", " + y + ") = " + result + " expected a value close to " + expected1;
21 }
22 var integerY = y | 0;
23 for (var i = 0; i < 10000; ++i) {
24 var result = mathPowDoubleInt1(x, integerY);
25 if (!valuesAreClose(result, expected2))
26 throw "Error: bad result, mathPowDoubleInt1(" + x + ", " + integerY + ") = " + result + " expected a value close to " + expected2;
27 }
28 }
29 noInline(test1);
30 test1(376.76522764377296, 10.81699226051569, 7.333951929109252e+27, 5.76378989575089e+25);
31
32 function mathPowDoubleDouble2(x, y) {
33 return Math.pow(x, y)
34 }
35 noInline(mathPowDoubleDouble2);
36
37 function mathPowDoubleInt2(x, y) {
38 return Math.pow(x, y)
39 }
40 noInline(mathPowDoubleInt2);
41 function test2(x, y, expected1, expected2) {
42 for (var i = 0; i < 10000; ++i) {
43 var result = mathPowDoubleDouble2(x, y);
44 if (!valuesAreClose(result, expected1))
45 throw "Error: bad result, mathPowDoubleDouble2(" + x + ", " + y + ") = " + result + " expected a value close to " + expected1;
46 }
47 var integerY = y | 0;
48 for (var i = 0; i < 10000; ++i) {
49 var result = mathPowDoubleInt2(x, integerY);
50 if (!valuesAreClose(result, expected2))
51 throw "Error: bad result, mathPowDoubleInt2(" + x + ", " + integerY + ") = " + result + " expected a value close to " + expected2;
52 }
53 }
54 noInline(test2);
55 test2(376.76522764377296, -5.81699226051569, 1.035180331187579e-15, 1.3171824310400265e-13);
56
57 function mathPowDoubleDouble3(x, y) {
58 return Math.pow(x, y)
59 }
60 noInline(mathPowDoubleDouble3);
61
62 function mathPowDoubleInt3(x, y) {
63 return Math.pow(x, y)
64 }
65 noInline(mathPowDoubleInt3);
66 function test3(x, y, expected1, expected2) {
67 for (var i = 0; i < 10000; ++i) {
68 var result = mathPowDoubleDouble3(x, y);
69 if (!valuesAreClose(result, expected1))
70 throw "Error: bad result, mathPowDoubleDouble3(" + x + ", " + y + ") = " + result + " expected a value close to " + expected1;
71 }
72 var integerY = y | 0;
73 for (var i = 0; i < 10000; ++i) {
74 var result = mathPowDoubleInt3(x, integerY);
75 if (!valuesAreClose(result, expected2))
76 throw "Error: bad result, mathPowDoubleInt3(" + x + ", " + integerY + ") = " + result + " expected a value close to " + expected2;
77 }
78 }
79 noInline(test3);
80 test3(-37.676522764377296, 10.0, 5763789895750892, 5763789895750892);
81
82 // Exponent zero.
83 function mathPowDoubleDouble4(x, y) {
84 return Math.pow(x, y)
85 }
86 noInline(mathPowDoubleDouble4);
87
88 function mathPowDoubleInt4(x, y) {
89 return Math.pow(x, y)
90 }
91 noInline(mathPowDoubleInt4);
92 function test4(x, y, expected1, expected2) {
93 for (var i = 0; i < 10000; ++i) {
94 var result = mathPowDoubleDouble4(x, y);
95 if (!valuesAreClose(result, expected1))
96 throw "Error: bad result, mathPowDoubleDouble4(" + x + ", " + y + ") = " + result + " expected a value close to " + expected1;
97 }
98 var integerY = y | 0;
99 for (var i = 0; i < 10000; ++i) {
100 var result = mathPowDoubleInt4(x, integerY);
101 if (!valuesAreClose(result, expected2))
102 throw "Error: bad result, mathPowDoubleInt4(" + x + ", " + integerY + ") = " + result + " expected a value close to " + expected2;
103 }
104 }
105 noInline(test4);
106 test4(-37.676522764377296, 0, 1, 1);
107
108 // Exponent minus zero.
109 function mathPowDoubleDouble5(x, y) {
110 return Math.pow(x, y)
111 }
112 noInline(mathPowDoubleDouble5);
113
114 function mathPowDoubleInt5(x, y) {
115 return Math.pow(x, y)
116 }
117 noInline(mathPowDoubleInt5);
118 function test5(x, y, expected1, expected2) {
119 for (var i = 0; i < 10000; ++i) {
120 var result = mathPowDoubleDouble5(x, y);
121 if (!valuesAreClose(result, expected1))
122 throw "Error: bad result, mathPowDoubleDouble5(" + x + ", " + y + ") = " + result + " expected a value close to " + expected1;
123 }
124 var integerY = y | 0;
125 for (var i = 0; i < 10000; ++i) {
126 var result = mathPowDoubleInt5(x, integerY);
127 if (!valuesAreClose(result, expected2))
128 throw "Error: bad result, mathPowDoubleInt(" + x + ", " + integerY + ") = " + result + " expected a value close to " + expected2;
129 }
130 }
131 noInline(test5);
132 test5(-37.676522764377296, -0, 1, 1);
133
134 // Exponent 1.
135 function mathPowDoubleDouble6(x, y) {
136 return Math.pow(x, y)
137 }
138 noInline(mathPowDoubleDouble6);
139
140 function mathPowDoubleInt6(x, y) {
141 return Math.pow(x, y)
142 }
143 noInline(mathPowDoubleInt6);
144 function test6(x, y, expected1, expected2) {
145 for (var i = 0; i < 10000; ++i) {
146 var result = mathPowDoubleDouble6(x, y);
147 if (!valuesAreClose(result, expected1))
148 throw "Error: bad result, mathPowDoubleDouble6(" + x + ", " + y + ") = " + result + " expected a value close to " + expected1;
149 }
150 var integerY = y | 0;
151 for (var i = 0; i < 10000; ++i) {
152 var result = mathPowDoubleInt6(x, integerY);
153 if (!valuesAreClose(result, expected2))
154 throw "Error: bad result, mathPowDoubleInt6(" + x + ", " + integerY + ") = " + result + " expected a value close to " + expected2;
155 }
156 }
157 noInline(test6);
158 test6(-37.676522764377296, 1.0, -37.676522764377296, -37.676522764377296);
159
160 // Exponent -1.
161 function mathPowDoubleDouble7(x, y) {
162 return Math.pow(x, y)
163 }
164 noInline(mathPowDoubleDouble7);
165
166 function mathPowDoubleInt7(x, y) {
167 return Math.pow(x, y)
168 }
169 noInline(mathPowDoubleInt7);
170 function test7(x, y, expected1, expected2) {
171 for (var i = 0; i < 10000; ++i) {
172 var result = mathPowDoubleDouble7(x, y);
173 if (!valuesAreClose(result, expected1))
174 throw "Error: bad result, mathPowDoubleDouble7(" + x + ", " + y + ") = " + result + " expected a value close to " + expected1;
175 }
176 var integerY = y | 0;
177 for (var i = 0; i < 10000; ++i) {
178 var result = mathPowDoubleDouble7(x, integerY);
179 if (!valuesAreClose(result, expected2))
180 throw "Error: bad result, mathPowDoubleDouble7(" + x + ", " + integerY + ") = " + result + " expected a value close to " + expected2;
181 }
182 }
183 noInline(test7);
184 test6(-37.676522764377296, -1.0, -0.026541727490454296, -0.026541727490454296);
185
186 // Let's square things.
187 function mathPowDoubleDouble8(x, y) {
188 return Math.pow(x, y)
189 }
190 noInline(mathPowDoubleDouble8);
191
192 function mathPowDoubleInt8(x, y) {
193 return Math.pow(x, y)
194 }
195 noInline(mathPowDoubleInt8);
196 function test8(x, y, expected1, expected2) {
197 for (var i = 0; i < 10000; ++i) {
198 var result = mathPowDoubleDouble8(x, y);
199 if (!valuesAreClose(result, expected1))
200 throw "Error: bad result, mathPowDoubleDouble8(" + x + ", " + y + ") = " + result + " expected a value close to " + expected1;
201 }
202 var integerY = y | 0;
203 for (var i = 0; i < 10000; ++i) {
204 var result = mathPowDoubleInt8(x, integerY);
205 if (!valuesAreClose(result, expected2))
206 throw "Error: bad result, mathPowDoubleInt8(" + x + ", " + integerY + ") = " + result + " expected a value close to " + expected2;
207 }
208 }
209 noInline(test8);
210 test7(-37.676522764377296, 2.0, 1419.5203676146407, 1419.5203676146407);
211
212 function mathPowDoubleDouble9(x, y) {
213 return Math.pow(x, y)
214 }
215 noInline(mathPowDoubleDouble9);
216
217 function mathPowDoubleInt9(x, y) {
218 return Math.pow(x, y)
219 }
220 noInline(mathPowDoubleInt9);
221 function test9(x, y, expected1, expected2) {
222 for (var i = 0; i < 10000; ++i) {
223 var result = mathPowDoubleDouble9(x, y);
224 if (!valuesAreClose(result, expected1))
225 throw "Error: bad result, mathPowDoubleDouble9(" + x + ", " + y + ") = " + result + " expected a value close to " + expected1;
226 }
227 var integerY = y | 0;
228 for (var i = 0; i < 10000; ++i) {
229 var result = mathPowDoubleInt9(x, integerY);
230 if (!valuesAreClose(result, expected2))
231 throw "Error: bad result, mathPowDoubleInt9(" + x + ", " + integerY + ") = " + result + " expected a value close to " + expected2;
232 }
233 }
234 noInline(test9);
235 test8(37.676522764377296, 2.0, 1419.5203676146407, 1419.5203676146407);
236
237 // Let's cube things.
238 function mathPowDoubleDouble10(x, y) {
239 return Math.pow(x, y)
240 }
241 noInline(mathPowDoubleDouble10);
242
243 function mathPowDoubleInt10(x, y) {
244 return Math.pow(x, y)
245 }
246 noInline(mathPowDoubleInt10);
247 function test10(x, y, expected1, expected2) {
248 for (var i = 0; i < 10000; ++i) {
249 var result = mathPowDoubleDouble10(x, y);
250 if (!valuesAreClose(result, expected1))
251 throw "Error: bad result, mathPowDoubleDouble(" + x + ", " + y + ") = " + result + " expected a value close to " + expected1;
252 }
253 var integerY = y | 0;
254 for (var i = 0; i < 10000; ++i) {
255 var result = mathPowDoubleInt10(x, integerY);
256 if (!valuesAreClose(result, expected2))
257 throw "Error: bad result, mathPowDoubleInt(" + x + ", " + integerY + ") = " + result + " expected a value close to " + expected2;
258 }
259 }
260 noInline(test9);
261 test9(-37.676522764377296, 3.0, -53482.591444930236, -53482.591444930236);
262
263 function mathPowDoubleDouble11(x, y) {
264 return Math.pow(x, y)
265 }
266 noInline(mathPowDoubleDouble11);
267
268 function mathPowDoubleInt11(x, y) {
269 return Math.pow(x, y)
270 }
271 noInline(mathPowDoubleInt11);
272 function test11(x, y, expected1, expected2) {
273 for (var i = 0; i < 10000; ++i) {
274 var result = mathPowDoubleDouble11(x, y);
275 if (!valuesAreClose(result, expected1))
276 throw "Error: bad result, mathPowDoubleDouble(" + x + ", " + y + ") = " + result + " expected a value close to " + expected1;
277 }
278 var integerY = y | 0;
279 for (var i = 0; i < 10000; ++i) {
280 var result = mathPowDoubleInt11(x, integerY);
281 if (!valuesAreClose(result, expected2))
282 throw "Error: bad result, mathPowDoubleInt(" + x + ", " + integerY + ") = " + result + " expected a value close to " + expected2;
283 }
284 }
285 noInline(test10);
286 test10(37.676522764377296, 3.0, 53482.591444930236, 53482.591444930236);