]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - tests/stress/math-pow-with-constants.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / math-pow-with-constants.js
... / ...
CommitLineData
1function exponentIsZero(x) {
2 return Math.pow(x, 0);
3}
4noInline(exponentIsZero);
5
6function testExponentIsZero() {
7 for (var i = 0; i < 10000; ++i) {
8 var result = exponentIsZero(5);
9 if (result !== 1)
10 throw "Error: zeroExponent(5) should be 1, was = " + result;
11 }
12 for (var i = 0; i < 10000; ++i) {
13 var result = exponentIsZero(5.5);
14 if (result !== 1)
15 throw "Error: zeroExponent(5.5) should be 1, was = " + result;
16 }
17}
18testExponentIsZero();
19
20
21function exponentIsOne(x) {
22 return Math.pow(x, 1);
23}
24noInline(exponentIsOne);
25
26function testExponentIsOne() {
27 for (var i = 0; i < 10000; ++i) {
28 var result = exponentIsOne(5);
29 if (result !== 5)
30 throw "Error: exponentIsOne(5) should be 5, was = " + result;
31 }
32 for (var i = 0; i < 10000; ++i) {
33 var result = exponentIsOne(5.5);
34 if (result !== 5.5)
35 throw "Error: exponentIsOne(5.5) should be 5.5, was = " + result;
36 }
37}
38testExponentIsOne();
39
40
41function powUsedAsSqrt(x) {
42 return Math.pow(x, 0.5);
43}
44noInline(powUsedAsSqrt);
45
46function testPowUsedAsSqrt() {
47 for (var i = 0; i < 10000; ++i) {
48 var result = powUsedAsSqrt(4);
49 if (result !== Math.sqrt(4))
50 throw "Error: powUsedAsSqrt(4) should be 2, was = " + result;
51 }
52 for (var i = 0; i < 10000; ++i) {
53 var result = powUsedAsSqrt(4.4);
54 if (result !== Math.sqrt(4.4))
55 throw "Error: powUsedAsSqrt(4) should be " + Math.sqrt(4.4) + ", was = " + result;
56 }
57
58}
59testPowUsedAsSqrt();
60
61
62function intIntConstantsSmallNumbers() {
63 return Math.pow(42, 3);
64}
65function intIntConstantsLargeNumbers() {
66 // The result does not fit in a integer.
67 return Math.pow(42, 42);
68}
69function intIntSmallConstants() {
70 return Math.pow(42, 3);
71}
72function intDoubleConstants() {
73 return Math.pow(14, 42.5);
74}
75function doubleDoubleConstants() {
76 return Math.pow(13.5, 42.5);
77}
78function doubleIntConstants() {
79 return Math.pow(13.5, 52);
80}
81noInline(intIntConstantsSmallNumbers);
82noInline(intIntConstantsLargeNumbers);
83noInline(intDoubleConstants);
84noInline(doubleDoubleConstants);
85noInline(doubleIntConstants);
86
87function testBaseAndExponentConstantLiterals()
88{
89 for (var i = 0; i < 10000; ++i) {
90 var result = intIntConstantsSmallNumbers();
91 if (result !== 74088)
92 throw "Error: intIntConstantsSmallNumbers() should be 74088, was = " + result;
93 }
94 for (var i = 0; i < 10000; ++i) {
95 var result = intIntConstantsLargeNumbers();
96 if (result !== 1.5013093754529656e+68)
97 throw "Error: intIntConstantsLargeNumbers() should be 1.5013093754529656e+68, was = " + result;
98 }
99 for (var i = 0; i < 10000; ++i) {
100 var result = intDoubleConstants();
101 if (result !== 5.1338303882015765e+48)
102 throw "Error: intDoubleConstants() should be 5.1338303882015765e+48, was = " + result;
103 }
104 for (var i = 0; i < 10000; ++i) {
105 var result = doubleDoubleConstants();
106 if (result !== 1.0944228729647829e+48)
107 throw "Error: doubleDoubleConstants() should be 1.0944228729647829e+48, was = " + result;
108 }
109 for (var i = 0; i < 10000; ++i) {
110 var result = doubleIntConstants();
111 if (result !== 5.989022735311158e+58)
112 throw "Error: doubleIntConstants() should be 5.989022735311158e+58, was = " + result;
113 }
114}
115testBaseAndExponentConstantLiterals();
116
117
118function exponentIsIntegerConstant(x) {
119 return Math.pow(x, 42);
120}
121noInline(exponentIsIntegerConstant);
122
123function testExponentIsIntegerConstant() {
124 for (var i = 0; i < 1000; ++i) {
125 var result = exponentIsIntegerConstant(2);
126 if (result !== 4398046511104)
127 throw "Error: exponentIsIntegerConstant(2) should be 4398046511104, was = " + result;
128 }
129 for (var i = 0; i < 1000; ++i) {
130 var result = exponentIsIntegerConstant(5);
131 if (result !== 2.2737367544323207e+29)
132 throw "Error: exponentIsIntegerConstant(5) should be 2.2737367544323207e+29, was = " + result;
133 }
134 for (var i = 0; i < 1000; ++i) {
135 var result = exponentIsIntegerConstant(2.1);
136 if (result !== 34135823067412.42)
137 throw "Error: exponentIsIntegerConstant(2.1) should be 34135823067412.42, was = " + result;
138 }
139}
140testExponentIsIntegerConstant();
141
142
143function exponentIsDoubleConstant(x) {
144 return Math.pow(x, 42.5);
145}
146noInline(exponentIsDoubleConstant);
147
148function testExponentIsDoubleConstant() {
149 for (var i = 0; i < 1000; ++i) {
150 var result = exponentIsDoubleConstant(2);
151 if (result !== 6219777023950.95)
152 throw "Error: exponentIsDoubleConstant(2) should be 6219777023950.95, was = " + result;
153 }
154 for (var i = 0; i < 1000; ++i) {
155 var result = exponentIsDoubleConstant(5);
156 if (result !== 5.084229945850415e+29)
157 throw "Error: exponentIsDoubleConstant(5) should be 5.084229945850415e+29, was = " + result;
158 }
159 for (var i = 0; i < 1000; ++i) {
160 var result = exponentIsDoubleConstant(2.1);
161 if (result !== 49467507261113.805)
162 throw "Error: exponentIsDoubleConstant(2.1) should be 49467507261113.805, was = " + result;
163 }
164}
165testExponentIsDoubleConstant();
166
167
168function exponentIsInfinityConstant(x) {
169 return Math.pow(x, Infinity);
170}
171noInline(exponentIsInfinityConstant);
172
173function testExponentIsInfinityConstant() {
174 for (var i = 0; i < 1000; ++i) {
175 var result = exponentIsInfinityConstant(2);
176 if (result !== Infinity)
177 throw "Error: exponentIsInfinityConstant(2) should be Infinity, was = " + result;
178 }
179 for (var i = 0; i < 1000; ++i) {
180 var result = exponentIsInfinityConstant(5);
181 if (result !== Infinity)
182 throw "Error: exponentIsInfinityConstant(5) should be Infinity, was = " + result;
183 }
184 for (var i = 0; i < 1000; ++i) {
185 var result = exponentIsInfinityConstant(2.1);
186 if (result !== Infinity)
187 throw "Error: exponentIsInfinityConstant(2.1) should be Infinity, was = " + result;
188 }
189}
190testExponentIsInfinityConstant();
191
192
193function exponentIsNegativeInfinityConstant(x) {
194 return Math.pow(x, -Infinity);
195}
196noInline(exponentIsNegativeInfinityConstant);
197
198function testExponentIsNegativeInfinityConstant() {
199 for (var i = 0; i < 1000; ++i) {
200 var result = exponentIsNegativeInfinityConstant(2);
201 if (result !== 0)
202 throw "Error: exponentIsNegativeInfinityConstant(2) should be zero, was = " + result;
203 }
204 for (var i = 0; i < 1000; ++i) {
205 var result = exponentIsNegativeInfinityConstant(5);
206 if (result !== 0)
207 throw "Error: exponentIsNegativeInfinityConstant(5) should be zero, was = " + result;
208 }
209 for (var i = 0; i < 1000; ++i) {
210 var result = exponentIsNegativeInfinityConstant(2.1);
211 if (result !== 0)
212 throw "Error: exponentIsNegativeInfinityConstant(2.1) should be zero, was = " + result;
213 }
214}
215testExponentIsNegativeInfinityConstant();