]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | function exponentIsZero(x) { |
2 | return Math.pow(x, 0); | |
3 | } | |
4 | noInline(exponentIsZero); | |
5 | ||
6 | function 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 | } | |
18 | testExponentIsZero(); | |
19 | ||
20 | ||
21 | function exponentIsOne(x) { | |
22 | return Math.pow(x, 1); | |
23 | } | |
24 | noInline(exponentIsOne); | |
25 | ||
26 | function 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 | } | |
38 | testExponentIsOne(); | |
39 | ||
40 | ||
41 | function powUsedAsSqrt(x) { | |
42 | return Math.pow(x, 0.5); | |
43 | } | |
44 | noInline(powUsedAsSqrt); | |
45 | ||
46 | function 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 | } | |
59 | testPowUsedAsSqrt(); | |
60 | ||
61 | ||
62 | function intIntConstantsSmallNumbers() { | |
63 | return Math.pow(42, 3); | |
64 | } | |
65 | function intIntConstantsLargeNumbers() { | |
66 | // The result does not fit in a integer. | |
67 | return Math.pow(42, 42); | |
68 | } | |
69 | function intIntSmallConstants() { | |
70 | return Math.pow(42, 3); | |
71 | } | |
72 | function intDoubleConstants() { | |
73 | return Math.pow(14, 42.5); | |
74 | } | |
75 | function doubleDoubleConstants() { | |
76 | return Math.pow(13.5, 42.5); | |
77 | } | |
78 | function doubleIntConstants() { | |
79 | return Math.pow(13.5, 52); | |
80 | } | |
81 | noInline(intIntConstantsSmallNumbers); | |
82 | noInline(intIntConstantsLargeNumbers); | |
83 | noInline(intDoubleConstants); | |
84 | noInline(doubleDoubleConstants); | |
85 | noInline(doubleIntConstants); | |
86 | ||
87 | function 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 | } | |
115 | testBaseAndExponentConstantLiterals(); | |
116 | ||
117 | ||
118 | function exponentIsIntegerConstant(x) { | |
119 | return Math.pow(x, 42); | |
120 | } | |
121 | noInline(exponentIsIntegerConstant); | |
122 | ||
123 | function 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 | } | |
140 | testExponentIsIntegerConstant(); | |
141 | ||
142 | ||
143 | function exponentIsDoubleConstant(x) { | |
144 | return Math.pow(x, 42.5); | |
145 | } | |
146 | noInline(exponentIsDoubleConstant); | |
147 | ||
148 | function 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 | } | |
165 | testExponentIsDoubleConstant(); | |
166 | ||
167 | ||
168 | function exponentIsInfinityConstant(x) { | |
169 | return Math.pow(x, Infinity); | |
170 | } | |
171 | noInline(exponentIsInfinityConstant); | |
172 | ||
173 | function 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 | } | |
190 | testExponentIsInfinityConstant(); | |
191 | ||
192 | ||
193 | function exponentIsNegativeInfinityConstant(x) { | |
194 | return Math.pow(x, -Infinity); | |
195 | } | |
196 | noInline(exponentIsNegativeInfinityConstant); | |
197 | ||
198 | function 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 | } | |
215 | testExponentIsNegativeInfinityConstant(); |