]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/arith-add-with-constants.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / arith-add-with-constants.js
CommitLineData
ed1e77d3
A
1// Test value + 0.
2function arithAddIdentityWrittenAsInteger(x) {
3 var a = x + 0;
4 var b = 0 + x;
5 if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
6 throw "Internal error on arithAddIdentityWrittenAsInteger, a = " + a + " b = " + b;
7 return a;
8}
9noInline(arithAddIdentityWrittenAsInteger);
10
11function testArithAddIdentityWrittenAsInteger() {
12 for (var i = 0; i < 1e4; ++i) {
13 var result = arithAddIdentityWrittenAsInteger(i);
14 if (result !== i) {
15 throw "arithAddIdentityWrittenAsInteger(i) = " + result + ", expected " + i;
16 }
17 }
18
19 for (var i = 0; i < 1e4; ++i) {
20 var result = arithAddIdentityWrittenAsInteger(-0);
21 if (result !== -0) {
22 throw "arithAddIdentityWrittenAsInteger(-0) = " + result + ", expected -0";
23 }
24 }
25
26 for (var i = 0; i < 1e4; ++i) {
27 var testValue = i + .5;
28 var result = arithAddIdentityWrittenAsInteger(testValue);
29 if (result !== testValue) {
30 throw "arithAddIdentityWrittenAsInteger(i) = " + result + ", expected " + testValue;
31 }
32 }
33
34 for (var i = 0; i < 1e4; ++i) {;
35 var result = arithAddIdentityWrittenAsInteger(NaN);
36 if (!isNaN(result)) {
37 throw "arithAddIdentityWrittenAsInteger(NaN) = " + result + ", expected NaN";
38 }
39 }
40
41 for (var i = 0; i < 1e4; ++i) {;
42 var result = arithAddIdentityWrittenAsInteger(Infinity);
43 if (isFinite(result)) {
44 throw "arithAddIdentityWrittenAsInteger(Infinity) = " + result + ", expected Infinity";
45 }
46 }
47
48 for (var i = 0; i < 1e4; ++i) {;
49 var result = arithAddIdentityWrittenAsInteger(-Infinity);
50 if (isFinite(result) || result >= 0) {
51 throw "arithAddIdentityWrittenAsInteger(-Infinity) = " + result + ", expected -Infinity";
52 }
53 }
54}
55testArithAddIdentityWrittenAsInteger();
56
57
58function arithAddIdentityWrittenAsDouble(x) {
59 var a = x + 0.0;
60 var b = 0. + x;
61 if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
62 throw "Internal error on arithAddIdentityWrittenAsDouble, a = " + a + " b = " + b;
63 return a;
64}
65noInline(arithAddIdentityWrittenAsDouble);
66
67function testArithAddIdentityWrittenAsDouble() {
68 for (var i = 0; i < 1e4; ++i) {
69 var result = arithAddIdentityWrittenAsDouble(i);
70 if (result !== i) {
71 throw "arithAddIdentityWrittenAsDouble(i) = " + result + ", expected " + i;
72 }
73 }
74
75 for (var i = 0; i < 1e4; ++i) {
76 var result = arithAddIdentityWrittenAsDouble(-0);
77 if (result !== -0) {
78 throw "arithAddIdentityWrittenAsDouble(-0) = " + result + ", expected -0 ";
79 }
80 }
81
82 for (var i = 0; i < 1e4; ++i) {
83 var testValue = i + .5;
84 var result = arithAddIdentityWrittenAsDouble(testValue);
85 if (result !== testValue) {
86 throw "arithAddIdentityWrittenAsDouble(i) = " + result + ", expected " + testValue;
87 }
88 }
89
90 for (var i = 0; i < 1e4; ++i) {;
91 var result = arithAddIdentityWrittenAsDouble(NaN);
92 if (!isNaN(result)) {
93 throw "arithAddIdentityWrittenAsDouble(NaN) = " + result + ", expected NaN";
94 }
95 }
96
97 for (var i = 0; i < 1e4; ++i) {;
98 var result = arithAddIdentityWrittenAsDouble(Infinity);
99 if (isFinite(result)) {
100 throw "arithAddIdentityWrittenAsDouble(Infinity) = " + result + ", expected Infinity";
101 }
102 }
103
104 for (var i = 0; i < 1e4; ++i) {;
105 var result = arithAddIdentityWrittenAsDouble(-Infinity);
106 if (isFinite(result) || result >= 0) {
107 throw "arithAddIdentityWrittenAsDouble(-Infinity) = " + result + ", expected -Infinity";
108 }
109 }
110}
111testArithAddIdentityWrittenAsDouble();
112
113
114// Test "value + 42".
115function arithAdd42WrittenAsInteger(x) {
116 var a = x + 42;
117 var b = 42 + x;
118 if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
119 throw "Internal error on arithAdd42WrittenAsInteger, a = " + a + " b = " + b;
120 return a;
121}
122noInline(arithAdd42WrittenAsInteger);
123
124function testArithAdd42WrittenAsInteger() {
125 for (var i = 0; i < 1e4; ++i) {
126 var result = arithAdd42WrittenAsInteger(13);
127 if (result !== 55) {
128 throw "arithAdd42WrittenAsInteger(13) = " + result + ", expected 55";
129 }
130 }
131
132 for (var i = 0; i < 1e4; ++i) {
133 var result = arithAdd42WrittenAsInteger(-0);
134 if (result !== 42) {
135 throw "arithAdd42WrittenAsInteger(-0) = " + result + ", expected 42";
136 }
137 }
138
139 for (var i = 0; i < 1e4; ++i) {
140 var result = arithAdd42WrittenAsInteger(13.3);
141 if (result !== 55.3) {
142 throw "arithAdd42WrittenAsInteger(13.3) = " + result + ", expected 55.3";
143 }
144 }
145
146 for (var i = 0; i < 1e4; ++i) {;
147 var result = arithAdd42WrittenAsInteger(NaN);
148 if (!isNaN(result)) {
149 throw "arithAdd42WrittenAsInteger(NaN) = " + result + ", expected NaN";
150 }
151 }
152
153 for (var i = 0; i < 1e4; ++i) {;
154 var result = arithAdd42WrittenAsInteger(Infinity);
155 if (isFinite(result)) {
156 throw "arithAdd42WrittenAsInteger(Infinity) = " + result + ", expected Infinity";
157 }
158 }
159
160 for (var i = 0; i < 1e4; ++i) {;
161 var result = arithAdd42WrittenAsInteger(-Infinity);
162 if (isFinite(result) || result >= 0) {
163 throw "arithAdd42WrittenAsInteger(-Infinity) = " + result + ", expected -Infinity";
164 }
165 }
166}
167testArithAdd42WrittenAsInteger();
168
169
170
171
172// Test "value + 42".
173function arithAdd42WrittenAsInteger(x) {
174 var a = x + 42;
175 var b = 42 + x;
176 if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
177 throw "Internal error on arithAdd42WrittenAsInteger, a = " + a + " b = " + b;
178 return a;
179}
180noInline(arithAdd42WrittenAsInteger);
181
182function testArithAdd42WrittenAsInteger() {
183 for (var i = 0; i < 1e4; ++i) {
184 var result = arithAdd42WrittenAsInteger(13);
185 if (result !== 55) {
186 throw "arithAdd42WrittenAsInteger(13) = " + result + ", expected 55";
187 }
188 }
189
190 for (var i = 0; i < 1e4; ++i) {
191 var result = arithAdd42WrittenAsInteger(-0);
192 if (result !== 42) {
193 throw "arithAdd42WrittenAsInteger(-0) = " + result + ", expected 42";
194 }
195 }
196
197 for (var i = 0; i < 1e4; ++i) {
198 var result = arithAdd42WrittenAsInteger(13.3);
199 if (result !== 55.3) {
200 throw "arithAdd42WrittenAsInteger(13.3) = " + result + ", expected 55.3";
201 }
202 }
203
204 for (var i = 0; i < 1e4; ++i) {;
205 var result = arithAdd42WrittenAsInteger(NaN);
206 if (!isNaN(result)) {
207 throw "arithAdd42WrittenAsInteger(NaN) = " + result + ", expected NaN";
208 }
209 }
210
211 for (var i = 0; i < 1e4; ++i) {;
212 var result = arithAdd42WrittenAsInteger(Infinity);
213 if (isFinite(result)) {
214 throw "arithAdd42WrittenAsInteger(Infinity) = " + result + ", expected Infinity";
215 }
216 }
217
218 for (var i = 0; i < 1e4; ++i) {;
219 var result = arithAdd42WrittenAsInteger(-Infinity);
220 if (isFinite(result) || result >= 0) {
221 throw "arithAdd42WrittenAsInteger(-Infinity) = " + result + ", expected -Infinity";
222 }
223 }
224}
225testArithAdd42WrittenAsInteger();
226
227function arithSub42WrittenAsDouble(x) {
228 var a = (x|0) - 42.0;
229 var b = -42. + (x|0);
230 if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
231 throw "Internal error on arithSub42WrittenAsDouble, a = " + a + " b = " + b;
232 return a;
233}
234noInline(arithSub42WrittenAsDouble);
235
236function testArithSub42WrittenAsDouble() {
237 for (var i = 0; i < 1e4; ++i) {
238 var result = arithSub42WrittenAsDouble(13);
239 if (result !== -29) {
240 throw "arithSub42WrittenAsDouble(13) = " + result + ", expected -29";
241 }
242 }
243
244 for (var i = 0; i < 1e4; ++i) {
245 var result = arithSub42WrittenAsDouble(-0);
246 if (result !== -42) {
247 throw "arithSub42WrittenAsDouble(-0) = " + result + ", expected -42";
248 }
249 }
250
251 for (var i = 0; i < 1e4; ++i) {
252 var result = arithSub42WrittenAsDouble(13.3);
253 if (result !== -29) {
254 throw "arithSub42WrittenAsDouble(13.3) = " + result + ", expected -29";
255 }
256 }
257}
258testArithSub42WrittenAsDouble();
259
260
261function doubleConstant(){
262 Math.min(0.0);
263 +0.0;
264} noInline(doubleConstant);
265
266function testDoubleConstant(){
267 for (var i = 0; i < 1e4; ++i) {
268 doubleConstant();
269 }
270}
271testDoubleConstant();