]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/math-pow-nan-behaviors.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / math-pow-nan-behaviors.js
1 // If y is NaN, the result is NaN.
2 function testIntegerBaseWithNaNExponentStatic() {
3 for (var i = 0; i < 10000; ++i) {
4 var result = Math.pow(5, NaN);
5 if (!isNaN(result))
6 throw "Error: bad result, Math.pow(5, NaN) = " + result;
7 }
8 for (var i = 0; i < 10000; ++i) {
9 var result = Math.pow(i, NaN);
10 if (!isNaN(result))
11 throw "Error: bad result, Math.pow(i, NaN) = " + result + " with i = " + i;
12 }
13 }
14 noInline(testIntegerBaseWithNaNExponentStatic);
15 testIntegerBaseWithNaNExponentStatic();
16
17 function mathPowIntegerBaseWithNaNExponentDynamic(x, y) {
18 return Math.pow(x, y);
19 }
20 noInline(mathPowIntegerBaseWithNaNExponentDynamic);
21 function testIntegerBaseWithNaNExponentDynamic() {
22 // Warm up with 2 integers.
23 for (var i = 0; i < 10000; ++i) {
24 var result = mathPowIntegerBaseWithNaNExponentDynamic(2, 5);
25 if (result !== 32)
26 throw "Error: bad result, mathPowIntegerBaseWithNaNExponentDynamic(2, 5) = " + result + ", expected 32."
27 }
28
29 for (var i = 0; i < 10000; ++i) {
30 var result = mathPowIntegerBaseWithNaNExponentDynamic(i, NaN);
31 if (!isNaN(result))
32 throw "Error: bad result, mathPowIntegerBaseWithNaNExponentDynamic(i, NaN) = " + result + " with i = " + i + ", expected NaN";
33 }
34 }
35 noInline(testIntegerBaseWithNaNExponentDynamic);
36 testIntegerBaseWithNaNExponentDynamic();
37
38 function testFloatingPointBaseWithNaNExponentStatic() {
39 for (var i = 0; i < 10000; ++i) {
40 var result = Math.pow(5.5, NaN);
41 if (!isNaN(result))
42 throw "Error: bad result, Math.pow(5.5, NaN) = " + result;
43 }
44 for (var i = 0; i < 10000; ++i) {
45 var result = Math.pow(i + 0.5, NaN);
46 if (!isNaN(result))
47 throw "Error: bad result, Math.pow(i + 0.5, NaN) = " + result + " with i = " + i;
48 }
49 }
50 noInline(testFloatingPointBaseWithNaNExponentStatic);
51 testFloatingPointBaseWithNaNExponentStatic();
52
53 function mathPowFloatingPointBaseWithNaNExponentDynamic(x, y) {
54 return Math.pow(x, y);
55 }
56 noInline(mathPowFloatingPointBaseWithNaNExponentDynamic);
57 function testFloatingPointBaseWithNaNExponentDynamic() {
58 // Warm up with 2 double.
59 for (var i = 0; i < 10000; ++i) {
60 var result = mathPowFloatingPointBaseWithNaNExponentDynamic(2.5, 5.1);
61 if (result !== 107.02717054543135)
62 throw "Error: bad result, mathPowFloatingPointBaseWithNaNExponentDynamic(2.5, 5.1) = " + result + ", expected 107.02717054543135."
63 }
64
65 for (var i = 0; i < 10000; ++i) {
66 var result = mathPowFloatingPointBaseWithNaNExponentDynamic(i + 0.5, NaN);
67 if (!isNaN(result))
68 throw "Error: bad result, mathPowFloatingPointBaseWithNaNExponentDynamic(i + 0.5, NaN) = " + result + " with i = " + i + ", expected NaN";
69 }
70 }
71 noInline(testFloatingPointBaseWithNaNExponentDynamic);
72 testFloatingPointBaseWithNaNExponentDynamic();
73
74 // If y is +0, the result is 1, even if x is NaN.
75 // If y is −0, the result is 1, even if x is NaN.
76 // If x is NaN and y is nonzero, the result is NaN.
77 function testNaNBaseStatic() {
78 for (var i = 0; i < 10000; ++i) {
79 var result = Math.pow(NaN, i + 1);
80 if (!isNaN(result))
81 throw "Error: bad result, Math.pow(NaN, i + 1) = " + result + " with i = " + i;
82 }
83 for (var i = 0; i < 10000; ++i) {
84 var result = Math.pow(NaN, i + 1.5);
85 if (!isNaN(result))
86 throw "Error: bad result, Math.pow(NaN, i + 1.5) = " + result + " with i = " + i;
87 }
88 for (var i = 0; i < 10000; ++i) {
89 var result = Math.pow(NaN, 0);
90 if (result !== 1)
91 throw "Error: bad result, Math.pow(NaN, 0) = " + result;
92 }
93 for (var i = 0; i < 10000; ++i) {
94 var result = Math.pow(NaN, -0);
95 if (result !== 1)
96 throw "Error: bad result, Math.pow(NaN, -0) = " + result;
97 }
98 }
99 noInline(testNaNBaseStatic);
100 testNaNBaseStatic();
101
102 function mathPowNaNBaseDynamic1(x, y) {
103 return Math.pow(x, y);
104 }
105 function mathPowNaNBaseDynamic2(x, y) {
106 return Math.pow(x, y);
107 }
108 function mathPowNaNBaseDynamic3(x, y) {
109 return Math.pow(x, y);
110 }
111 function mathPowNaNBaseDynamic4(x, y) {
112 return Math.pow(x, y);
113 }
114 noInline(mathPowNaNBaseDynamic1);
115 noInline(mathPowNaNBaseDynamic2);
116 noInline(mathPowNaNBaseDynamic3);
117 noInline(mathPowNaNBaseDynamic4);
118 function testNaNBaseDynamic() {
119 for (var i = 0; i < 10000; ++i) {
120 var result = mathPowNaNBaseDynamic1(NaN, i + 1);
121 if (!isNaN(result))
122 throw "Error: bad result, mathPowNaNBaseDynamic1(NaN, i + 1) = " + result + " with i = " + i;
123 }
124 for (var i = 0; i < 10000; ++i) {
125 var result = mathPowNaNBaseDynamic2(NaN, i + 1.5);
126 if (!isNaN(result))
127 throw "Error: bad result, mathPowNaNBaseDynamic2(NaN, i + 1.5) = " + result + " with i = " + i;
128 }
129 for (var i = 0; i < 10000; ++i) {
130 var result = mathPowNaNBaseDynamic3(NaN, 0);
131 if (result !== 1)
132 throw "Error: bad result, mathPowNaNBaseDynamic3(NaN, 0) = " + result;
133 }
134 for (var i = 0; i < 10000; ++i) {
135 var result = mathPowNaNBaseDynamic4(NaN, -0);
136 if (result !== 1)
137 throw "Error: bad result, mathPowNaNBaseDynamic4(NaN, -0) = " + result;
138 }
139 }
140 noInline(testNaNBaseDynamic);
141 testNaNBaseDynamic();
142
143 // If abs(x) is 1 and y is +∞, the result is NaN.
144 // If abs(x) is 1 and y is −∞, the result is NaN.
145 function infiniteExponentsStatic() {
146 for (var i = 0; i < 10000; ++i) {
147 var result = Math.pow(1, Number.POSITIVE_INFINITY);
148 if (!isNaN(result))
149 throw "Error: bad result, Math.pow(1, Number.POSITIVE_INFINITY) = " + result;
150 }
151 for (var i = 0; i < 10000; ++i) {
152 var result = Math.pow(-1, Number.POSITIVE_INFINITY);
153 if (!isNaN(result))
154 throw "Error: bad result, Math.pow(-1, Number.POSITIVE_INFINITY) = " + result;
155 }
156 for (var i = 0; i < 10000; ++i) {
157 var result = Math.pow(1, Number.NEGATIVE_INFINITY);
158 if (!isNaN(result))
159 throw "Error: bad result, Math.pow(1, Number.NEGATIVE_INFINITY) = " + result;
160 }
161 for (var i = 0; i < 10000; ++i) {
162 var result = Math.pow(-1, Number.NEGATIVE_INFINITY);
163 if (!isNaN(result))
164 throw "Error: bad result, Math.pow(-1, Number.NEGATIVE_INFINITY) = " + result;
165 }
166 }
167 noInline(infiniteExponentsStatic);
168 infiniteExponentsStatic();
169
170 function mathPowInfiniteExponentsDynamic1(x, y) {
171 return Math.pow(x, y);
172 }
173 function mathPowInfiniteExponentsDynamic2(x, y) {
174 return Math.pow(x, y);
175 }
176 function mathPowInfiniteExponentsDynamic3(x, y) {
177 return Math.pow(x, y);
178 }
179 function mathPowInfiniteExponentsDynamic4(x, y) {
180 return Math.pow(x, y);
181 }
182 noInline(mathPowInfiniteExponentsDynamic1);
183 noInline(mathPowInfiniteExponentsDynamic2);
184 noInline(mathPowInfiniteExponentsDynamic3);
185 noInline(mathPowInfiniteExponentsDynamic4);
186 function infiniteExponentsDynamic() {
187 for (var i = 0; i < 10000; ++i) {
188 var result = mathPowInfiniteExponentsDynamic1(1, Number.POSITIVE_INFINITY);
189 if (!isNaN(result))
190 throw "Error: bad result, mathPowInfiniteExponentsDynamic1(1, Number.POSITIVE_INFINITY) = " + result;
191 }
192 for (var i = 0; i < 10000; ++i) {
193 var result = mathPowInfiniteExponentsDynamic2(-1, Number.POSITIVE_INFINITY);
194 if (!isNaN(result))
195 throw "Error: bad result, mathPowInfiniteExponentsDynamic2(-1, Number.POSITIVE_INFINITY) = " + result;
196 }
197 for (var i = 0; i < 10000; ++i) {
198 var result = mathPowInfiniteExponentsDynamic3(1, Number.NEGATIVE_INFINITY);
199 if (!isNaN(result))
200 throw "Error: bad result, mathPowInfiniteExponentsDynamic3(1, Number.NEGATIVE_INFINITY) = " + result;
201 }
202 for (var i = 0; i < 10000; ++i) {
203 var result = mathPowInfiniteExponentsDynamic4(-1, Number.NEGATIVE_INFINITY);
204 if (!isNaN(result))
205 throw "Error: bad result, mathPowInfiniteExponentsDynamic4(-1, Number.NEGATIVE_INFINITY) = " + result;
206 }
207 }
208 noInline(infiniteExponentsDynamic);
209 infiniteExponentsDynamic();