]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/math-pow-basics.js
1 function valuesAreClose(a
, b
) {
2 return Math
.abs(a
/ b
) - 1 < 1e-10;
6 function mathPowDoubleDouble1(x
, y
) {
9 noInline(mathPowDoubleDouble1
);
11 function mathPowDoubleInt1(x
, y
) {
14 noInline(mathPowDoubleInt1
);
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
;
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
;
30 test1(376.76522764377296, 10.81699226051569, 7.333951929109252e+27, 5.76378989575089e+25);
32 function mathPowDoubleDouble2(x
, y
) {
35 noInline(mathPowDoubleDouble2
);
37 function mathPowDoubleInt2(x
, y
) {
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
;
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
;
55 test2(376.76522764377296, -5.81699226051569, 1.035180331187579e-15, 1.3171824310400265e-13);
57 function mathPowDoubleDouble3(x
, y
) {
60 noInline(mathPowDoubleDouble3
);
62 function mathPowDoubleInt3(x
, y
) {
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
;
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
;
80 test3(-37.676522764377296, 10.0, 5763789895750892, 5763789895750892);
83 function mathPowDoubleDouble4(x
, y
) {
86 noInline(mathPowDoubleDouble4
);
88 function mathPowDoubleInt4(x
, y
) {
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
;
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
;
106 test4(-37.676522764377296, 0, 1, 1);
108 // Exponent minus zero.
109 function mathPowDoubleDouble5(x
, y
) {
110 return Math
.pow(x
, y
)
112 noInline(mathPowDoubleDouble5
);
114 function mathPowDoubleInt5(x
, y
) {
115 return Math
.pow(x
, y
)
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
;
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
;
132 test5(-37.676522764377296, -0, 1, 1);
135 function mathPowDoubleDouble6(x
, y
) {
136 return Math
.pow(x
, y
)
138 noInline(mathPowDoubleDouble6
);
140 function mathPowDoubleInt6(x
, y
) {
141 return Math
.pow(x
, y
)
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
;
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
;
158 test6(-37.676522764377296, 1.0, -37.676522764377296, -37.676522764377296);
161 function mathPowDoubleDouble7(x
, y
) {
162 return Math
.pow(x
, y
)
164 noInline(mathPowDoubleDouble7
);
166 function mathPowDoubleInt7(x
, y
) {
167 return Math
.pow(x
, y
)
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
;
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
;
184 test6(-37.676522764377296, -1.0, -0.026541727490454296, -0.026541727490454296);
186 // Let's square things.
187 function mathPowDoubleDouble8(x
, y
) {
188 return Math
.pow(x
, y
)
190 noInline(mathPowDoubleDouble8
);
192 function mathPowDoubleInt8(x
, y
) {
193 return Math
.pow(x
, y
)
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
;
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
;
210 test7(-37.676522764377296, 2.0, 1419.5203676146407, 1419.5203676146407);
212 function mathPowDoubleDouble9(x
, y
) {
213 return Math
.pow(x
, y
)
215 noInline(mathPowDoubleDouble9
);
217 function mathPowDoubleInt9(x
, y
) {
218 return Math
.pow(x
, y
)
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
;
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
;
235 test8(37.676522764377296, 2.0, 1419.5203676146407, 1419.5203676146407);
237 // Let's cube things.
238 function mathPowDoubleDouble10(x
, y
) {
239 return Math
.pow(x
, y
)
241 noInline(mathPowDoubleDouble10
);
243 function mathPowDoubleInt10(x
, y
) {
244 return Math
.pow(x
, y
)
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
;
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
;
261 test9(-37.676522764377296, 3.0, -53482.591444930236, -53482.591444930236);
263 function mathPowDoubleDouble11(x
, y
) {
264 return Math
.pow(x
, y
)
266 noInline(mathPowDoubleDouble11
);
268 function mathPowDoubleInt11(x
, y
) {
269 return Math
.pow(x
, y
)
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
;
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
;
286 test10(37.676522764377296, 3.0, 53482.591444930236, 53482.591444930236);