]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/arith-mul-with-constants.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / arith-mul-with-constants.js
1 // Test value * 1.
2 function arithMulIdentityWrittenAsInteger(x) {
3 var a = x * 1;
4 var b = 1 * x;
5 if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
6 throw "Internal error on arithMulIdentityWrittenAsInteger, a = " + a + " b = " + b;
7 return a;
8 }
9 noInline(arithMulIdentityWrittenAsInteger);
10
11 function testArithMulIdentityWrittenAsInteger() {
12 for (var i = 0; i < 1e4; ++i) {
13 var result = arithMulIdentityWrittenAsInteger(i);
14 if (result !== i) {
15 throw "arithMulIdentityWrittenAsInteger(i) = " + result + ", expected " + i;
16 }
17 }
18
19 for (var i = 0; i < 1e4; ++i) {
20 var result = arithMulIdentityWrittenAsInteger(-0);
21 if (result !== -0) {
22 throw "arithMulIdentityWrittenAsInteger(-0) = " + result + ", expected -0";
23 }
24 }
25
26 for (var i = 0; i < 1e4; ++i) {
27 var testValue = i + .5;
28 var result = arithMulIdentityWrittenAsInteger(testValue);
29 if (result !== testValue) {
30 throw "arithMulIdentityWrittenAsInteger(i) = " + result + ", expected " + testValue;
31 }
32 }
33
34 for (var i = 0; i < 1e4; ++i) {;
35 var result = arithMulIdentityWrittenAsInteger(NaN);
36 if (!isNaN(result)) {
37 throw "arithMulIdentityWrittenAsInteger(NaN) = " + result + ", expected NaN";
38 }
39 }
40
41 for (var i = 0; i < 1e4; ++i) {;
42 var result = arithMulIdentityWrittenAsInteger(Infinity);
43 if (isFinite(result)) {
44 throw "arithMulIdentityWrittenAsInteger(Infinity) = " + result + ", expected Infinity";
45 }
46 }
47
48 for (var i = 0; i < 1e4; ++i) {;
49 var result = arithMulIdentityWrittenAsInteger(-Infinity);
50 if (isFinite(result) || result >= 0) {
51 throw "arithMulIdentityWrittenAsInteger(-Infinity) = " + result + ", expected -Infinity";
52 }
53 }
54 }
55 testArithMulIdentityWrittenAsInteger();
56
57
58 function arithMulIdentityWrittenAsDouble(x) {
59 var a = x * 1.0;
60 var b = 1. * x;
61 if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
62 throw "Internal error on arithMulIdentityWrittenAsDouble, a = " + a + " b = " + b;
63 return a;
64 }
65 noInline(arithMulIdentityWrittenAsDouble);
66
67 function testArithMulIdentityWrittenAsDouble() {
68 for (var i = 0; i < 1e4; ++i) {
69 var result = arithMulIdentityWrittenAsDouble(i);
70 if (result !== i) {
71 throw "arithMulIdentityWrittenAsDouble(i) = " + result + ", expected " + i;
72 }
73 }
74
75 for (var i = 0; i < 1e4; ++i) {
76 var result = arithMulIdentityWrittenAsDouble(-0);
77 if (result !== -0) {
78 throw "arithMulIdentityWrittenAsDouble(-0) = " + result + ", expected -0 ";
79 }
80 }
81
82 for (var i = 0; i < 1e4; ++i) {
83 var testValue = i + .5;
84 var result = arithMulIdentityWrittenAsDouble(testValue);
85 if (result !== testValue) {
86 throw "arithMulIdentityWrittenAsDouble(i) = " + result + ", expected " + testValue;
87 }
88 }
89
90 for (var i = 0; i < 1e4; ++i) {;
91 var result = arithMulIdentityWrittenAsDouble(NaN);
92 if (!isNaN(result)) {
93 throw "arithMulIdentityWrittenAsDouble(NaN) = " + result + ", expected NaN";
94 }
95 }
96
97 for (var i = 0; i < 1e4; ++i) {;
98 var result = arithMulIdentityWrittenAsDouble(Infinity);
99 if (isFinite(result)) {
100 throw "arithMulIdentityWrittenAsDouble(Infinity) = " + result + ", expected Infinity";
101 }
102 }
103
104 for (var i = 0; i < 1e4; ++i) {;
105 var result = arithMulIdentityWrittenAsDouble(-Infinity);
106 if (isFinite(result) || result >= 0) {
107 throw "arithMulIdentityWrittenAsDouble(-Infinity) = " + result + ", expected -Infinity";
108 }
109 }
110 }
111 testArithMulIdentityWrittenAsDouble();
112
113
114 // Test "value * 42".
115 function arithMul42WrittenAsInteger(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 arithMul42WrittenAsInteger, a = " + a + " b = " + b;
120 return a;
121 }
122 noInline(arithMul42WrittenAsInteger);
123
124 function testArithMul42WrittenAsInteger() {
125 for (var i = 0; i < 1e4; ++i) {
126 var result = arithMul42WrittenAsInteger(13);
127 if (result !== 546) {
128 throw "arithMul42WrittenAsInteger(13) = " + result + ", expected 546";
129 }
130 }
131
132 for (var i = 0; i < 1e4; ++i) {
133 var result = arithMul42WrittenAsInteger(-0);
134 if (result !== -0) {
135 throw "arithMul42WrittenAsInteger(-0) = " + result + ", expected -0";
136 }
137 }
138
139 for (var i = 0; i < 1e4; ++i) {
140 var result = arithMul42WrittenAsInteger(13.3);
141 if (result !== 558.6) {
142 throw "arithMul42WrittenAsInteger(13.3) = " + result + ", expected 558.6";
143 }
144 }
145
146 for (var i = 0; i < 1e4; ++i) {;
147 var result = arithMul42WrittenAsInteger(NaN);
148 if (!isNaN(result)) {
149 throw "arithMul42WrittenAsInteger(NaN) = " + result + ", expected NaN";
150 }
151 }
152
153 for (var i = 0; i < 1e4; ++i) {;
154 var result = arithMul42WrittenAsInteger(Infinity);
155 if (isFinite(result)) {
156 throw "arithMul42WrittenAsInteger(Infinity) = " + result + ", expected Infinity";
157 }
158 }
159
160 for (var i = 0; i < 1e4; ++i) {;
161 var result = arithMul42WrittenAsInteger(-Infinity);
162 if (isFinite(result) || result >= 0) {
163 throw "arithMul42WrittenAsInteger(-Infinity) = " + result + ", expected -Infinity";
164 }
165 }
166 }
167 testArithMul42WrittenAsInteger();
168
169
170 function arithMul42WrittenAsDouble(x) {
171 var a = x * 42.0;
172 var b = 42. * x;
173 if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
174 throw "Internal error on arithMul42WrittenAsDouble, a = " + a + " b = " + b;
175 return a;
176 }
177 noInline(arithMul42WrittenAsDouble);
178
179 function testArithMul42WrittenAsDouble() {
180 for (var i = 0; i < 1e4; ++i) {
181 var result = arithMul42WrittenAsDouble(13);
182 if (result !== 546) {
183 throw "arithMul42WrittenAsDouble(i) = " + result + ", expected 546";
184 }
185 }
186
187 for (var i = 0; i < 1e4; ++i) {
188 var result = arithMul42WrittenAsDouble(-0);
189 if (result !== -0) {
190 throw "arithMul42WrittenAsDouble(-0) = " + result + ", expected -0";
191 }
192 }
193
194 for (var i = 0; i < 1e4; ++i) {
195 var result = arithMul42WrittenAsDouble(13.3);
196 if (result !== 558.6) {
197 throw "arithMul42WrittenAsDouble(13.3) = " + result + ", expected 558.6";
198 }
199 }
200
201 for (var i = 0; i < 1e4; ++i) {;
202 var result = arithMul42WrittenAsDouble(NaN);
203 if (!isNaN(result)) {
204 throw "arithMul42WrittenAsDouble(NaN) = " + result + ", expected NaN";
205 }
206 }
207
208 for (var i = 0; i < 1e4; ++i) {;
209 var result = arithMul42WrittenAsDouble(Infinity);
210 if (isFinite(result)) {
211 throw "arithMul42WrittenAsDouble(Infinity) = " + result + ", expected Infinity";
212 }
213 }
214
215 for (var i = 0; i < 1e4; ++i) {;
216 var result = arithMul42WrittenAsDouble(-Infinity);
217 if (isFinite(result) || result >= 0) {
218 throw "arithMul42WrittenAsDouble(-Infinity) = " + result + ", expected -Infinity";
219 }
220 }
221 }
222 testArithMul42WrittenAsDouble();