Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 //-----------------------------------------------------------------------------
7 var BUGNUMBER = 'none';
8 var summary = 'trace-capability math mini-testsuite';
10 printBugNumber(BUGNUMBER);
11 printStatus (summary);
13 jit(true);
15 /**
16 * A number of the tests in this file depend on the setting of
17 * HOTLOOP. Define some constants up front, so they're easy to grep
18 * for.
19 */
20 // The HOTLOOP constant we depend on; only readable from our stats
21 // object in debug builds.
22 const haveTracemonkey = !!(this.tracemonkey)
23 const HOTLOOP = haveTracemonkey ? tracemonkey.HOTLOOP : 2;
25 var testName = null;
26 if ("arguments" in this && arguments.length > 0)
27 testName = arguments[0];
28 var fails = [], passes=[];
30 function jitstatHandler(f)
31 {
32 if (!haveTracemonkey)
33 return;
35 // XXXbz this is a nasty hack, but I can't figure out a way to
36 // just use jitstats.tbl here
37 f("recorderStarted");
38 f("recorderAborted");
39 f("traceCompleted");
40 f("sideExitIntoInterpreter");
41 f("typeMapMismatchAtEntry");
42 f("returnToDifferentLoopHeader");
43 f("traceTriggered");
44 f("globalShapeMismatchAtEntry");
45 f("treesTrashed");
46 f("slotPromoted");
47 f("unstableLoopVariable");
48 f("noCompatInnerTrees");
49 f("breakLoopExits");
50 f("returnLoopExits");
51 }
53 function test(f)
54 {
55 if (!testName || testName == f.name) {
56 // Collect our jit stats
57 var localJITstats = {};
58 jitstatHandler(function(prop, local, global) {
59 localJITstats[prop] = tracemonkey[prop];
60 });
61 check(f.name, f(), f.expected, localJITstats, f.jitstats);
62 }
63 }
65 function map_test(t, cases)
66 {
67 for (var i = 0; i < cases.length; i++) {
68 function c() { return t(cases[i].input); }
69 c.expected = cases[i].expected;
70 c.name = t.name + "(" + uneval(cases[i].input) + ")";
71 test(c);
72 }
73 }
75 // Use this function to compare expected and actual test results.
76 // Types must match.
77 // For numbers, treat NaN as matching NaN, distinguish 0 and -0, and
78 // tolerate a certain degree of error for other values.
79 //
80 // These are the same criteria used by the tests in js/tests, except that
81 // we distinguish 0 and -0.
82 function close_enough(expected, actual)
83 {
84 if (typeof expected != typeof actual)
85 return false;
86 if (typeof expected != 'number')
87 return actual == expected;
89 // Distinguish NaN from other values. Using x != x comparisons here
90 // works even if tests redefine isNaN.
91 if (actual != actual)
92 return expected != expected
93 if (expected != expected)
94 return false;
96 // Tolerate a certain degree of error.
97 if (actual != expected)
98 return Math.abs(actual - expected) <= 1E-10;
100 // Distinguish 0 and -0.
101 if (actual == 0)
102 return (1 / actual > 0) == (1 / expected > 0);
104 return true;
105 }
107 function check(desc, actual, expected, oldJITstats, expectedJITstats)
108 {
109 var pass = false;
110 if (close_enough(expected, actual)) {
111 pass = true;
112 jitstatHandler(function(prop) {
113 if (expectedJITstats && prop in expectedJITstats &&
114 expectedJITstats[prop] !=
115 tracemonkey[prop] - oldJITstats[prop]) {
116 pass = false;
117 }
118 });
119 if (pass) {
120 reportCompare(expected, actual, desc);
121 passes.push(desc);
122 return print(desc, ": passed");
123 }
124 }
126 if (expected instanceof RegExp) {
127 pass = reportMatch(expected, actual + '', desc);
128 if (pass) {
129 jitstatHandler(function(prop) {
130 if (expectedJITstats && prop in expectedJITstats &&
131 expectedJITstats[prop] !=
132 tracemonkey[prop] - oldJITstats[prop]) {
133 pass = false;
134 }
135 });
136 }
137 if (pass) {
138 passes.push(desc);
139 return print(desc, ": passed");
140 }
141 }
143 reportCompare(expected, actual, desc);
145 fails.push(desc);
146 var expectedStats = "";
147 if (expectedJITstats) {
148 jitstatHandler(function(prop) {
149 if (prop in expectedJITstats) {
150 if (expectedStats)
151 expectedStats += " ";
152 expectedStats +=
153 prop + ": " + expectedJITstats[prop];
154 }
155 });
156 }
157 var actualStats = "";
158 if (expectedJITstats) {
159 jitstatHandler(function(prop) {
160 if (prop in expectedJITstats) {
161 if (actualStats)
162 actualStats += " ";
163 actualStats += prop + ": " + (tracemonkey[prop]-oldJITstats[prop]);
164 }
165 });
166 }
167 print(desc, ": FAILED: expected", typeof(expected),
168 "(", uneval(expected), ")",
169 (expectedStats ? " [" + expectedStats + "] " : ""),
170 "!= actual",
171 typeof(actual), "(", uneval(actual), ")",
172 (actualStats ? " [" + actualStats + "] " : ""));
173 }
175 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
177 // Apply FUNCNAME to ARGS, and check against EXPECTED.
178 // Expect a loop containing such a call to be traced.
179 // FUNCNAME and ARGS are both strings.
180 // ARGS has the form of an argument list: a comma-separated list of expressions.
181 // Certain Tracemonkey limitations require us to pass FUNCNAME as a string.
182 // Passing ARGS as a string allows us to assign better test names:
183 // expressions like Math.PI/4 haven't been evaluated to big hairy numbers.
184 function testmath(funcname, args, expected) {
185 var i, j;
187 var arg_value_list = eval("[" + args + "]");
188 var arity = arg_value_list.length;
190 // Build the string "a[i][0],...,a[i][ARITY-1]".
191 var actuals = []
192 for (i = 0; i < arity; i++)
193 actuals.push("a[i][" + i + "]");
194 actuals = actuals.join(",");
196 // Create a function that maps FUNCNAME across an array of input values.
197 // Unless we eval here, the call to funcname won't get traced.
198 // FUNCNAME="Infinity/Math.abs" and cases like that happen to
199 // parse, too, in a twisted way.
200 var mapfunc = eval("(function(a) {\n"
201 + " for (var i = 0; i < a.length; i++)\n"
202 + " a[i] = " + funcname + "(" + actuals +");\n"
203 + " })\n");
205 // To prevent the compiler from doing constant folding, produce an
206 // array to pass to mapfunc that contains enough dummy
207 // values at the front to get the loop body jitted, and then our
208 // actual test value.
209 var dummies_and_input = [];
210 for (i = 0; i < RUNLOOP; i++) {
211 var dummy_list = [];
212 for (j = 0; j < arity; j++)
213 dummy_list[j] = .0078125 * ((i + j) % 128);
214 dummies_and_input[i] = dummy_list;
215 }
216 dummies_and_input[RUNLOOP] = arg_value_list;
218 function testfunc() {
219 // Map the function across the dummy values and the test input.
220 mapfunc(dummies_and_input);
221 return dummies_and_input[RUNLOOP];
222 }
223 testfunc.name = funcname + "(" + args + ")";
224 testfunc.expected = expected;
226 // Disable jitstats check. This never worked right. The actual part of the
227 // loop we cared about was never traced. We traced the filler parts early
228 // and then took a mismatch side exit on every subequent array read with
229 // a different type (gal, discovered when fixing bug 479110).
230 // testfunc.jitstats = {
231 // recorderStarted: 1,
232 // recorderAborted: 0,
233 // traceTriggered: 1
234 // };
236 test(testfunc);
237 }
239 testmath("Math.abs", "void 0", Number.NaN)
240 testmath("Math.abs", "null", 0)
241 testmath("Math.abs", "true", 1)
242 testmath("Math.abs", "false", 0)
243 testmath("Math.abs", "\"a string primitive\"", Number.NaN)
244 testmath("Math.abs", "new String( 'a String object' )", Number.NaN)
245 testmath("Math.abs", "Number.NaN", Number.NaN)
246 testmath("Math.abs", "0", 0)
247 testmath("Math.abs", "-0", 0)
248 testmath("Infinity/Math.abs", "-0", Infinity)
249 testmath("Math.abs", "Number.NEGATIVE_INFINITY", Number.POSITIVE_INFINITY)
250 testmath("Math.abs", "Number.POSITIVE_INFINITY", Number.POSITIVE_INFINITY)
251 testmath("Math.abs", "- Number.MAX_VALUE", Number.MAX_VALUE)
252 testmath("Math.abs", "-Number.MIN_VALUE", Number.MIN_VALUE)
253 testmath("Math.abs", "Number.MAX_VALUE", Number.MAX_VALUE)
254 testmath("Math.abs", "Number.MIN_VALUE", Number.MIN_VALUE)
255 testmath("Math.abs", "-1", 1)
256 testmath("Math.abs", "new Number(-1)", 1)
257 testmath("Math.abs", "1", 1)
258 testmath("Math.abs", "Math.PI", Math.PI)
259 testmath("Math.abs", "-Math.PI", Math.PI)
260 testmath("Math.abs", "-1/100000000", 1/100000000)
261 testmath("Math.abs", "-Math.pow(2,32)", Math.pow(2,32))
262 testmath("Math.abs", "Math.pow(2,32)", Math.pow(2,32))
263 testmath("Math.abs", "-0xfff", 4095)
264 testmath("Math.abs", "-0777", 511)
265 testmath("Math.abs", "'-1e-1'", 0.1)
266 testmath("Math.abs", "'0xff'", 255)
267 testmath("Math.abs", "'077'", 77)
268 testmath("Math.abs", "'Infinity'", Infinity)
269 testmath("Math.abs", "'-Infinity'", Infinity)
271 testmath("Math.acos", "void 0", Number.NaN)
272 testmath("Math.acos", "null", Math.PI/2)
273 testmath("Math.acos", "Number.NaN", Number.NaN)
274 testmath("Math.acos", "\"a string\"", Number.NaN)
275 testmath("Math.acos", "'0'", Math.PI/2)
276 testmath("Math.acos", "'1'", 0)
277 testmath("Math.acos", "'-1'", Math.PI)
278 testmath("Math.acos", "1.00000001", Number.NaN)
279 testmath("Math.acos", "-1.00000001", Number.NaN)
280 testmath("Math.acos", "1", 0)
281 testmath("Math.acos", "-1", Math.PI)
282 testmath("Math.acos", "0", Math.PI/2)
283 testmath("Math.acos", "-0", Math.PI/2)
284 testmath("Math.acos", "Math.SQRT1_2", Math.PI/4)
285 testmath("Math.acos", "-Math.SQRT1_2", Math.PI/4*3)
286 testmath("Math.acos", "0.9999619230642", Math.PI/360)
287 testmath("Math.acos", "-3.0", Number.NaN)
289 testmath("Math.asin", "void 0", Number.NaN)
290 testmath("Math.asin", "null", 0)
291 testmath("Math.asin", "Number.NaN", Number.NaN)
292 testmath("Math.asin", "\"string\"", Number.NaN)
293 testmath("Math.asin", "\"0\"", 0)
294 testmath("Math.asin", "\"1\"", Math.PI/2)
295 testmath("Math.asin", "\"-1\"", -Math.PI/2)
296 testmath("Math.asin", "Math.SQRT1_2+''", Math.PI/4)
297 testmath("Math.asin", "-Math.SQRT1_2+''", -Math.PI/4)
298 testmath("Math.asin", "1.000001", Number.NaN)
299 testmath("Math.asin", "-1.000001", Number.NaN)
300 testmath("Math.asin", "0", 0)
301 testmath("Math.asin", "-0", -0)
302 testmath("Infinity/Math.asin", "-0", -Infinity)
303 testmath("Math.asin", "1", Math.PI/2)
304 testmath("Math.asin", "-1", -Math.PI/2)
305 testmath("Math.asin", "Math.SQRT1_2", Math.PI/4)
306 testmath("Math.asin", "-Math.SQRT1_2", -Math.PI/4)
308 testmath("Math.atan", "void 0", Number.NaN)
309 testmath("Math.atan", "null", 0)
310 testmath("Math.atan", "Number.NaN", Number.NaN)
311 testmath("Math.atan", "\"a string\"", Number.NaN)
312 testmath("Math.atan", "'0'", 0)
313 testmath("Math.atan", "'1'", Math.PI/4)
314 testmath("Math.atan", "'-1'", -Math.PI/4)
315 testmath("Math.atan", "'Infinity'", Math.PI/2)
316 testmath("Math.atan", "'-Infinity'", -Math.PI/2)
317 testmath("Math.atan", "0", 0)
318 testmath("Math.atan", "-0", -0)
319 testmath("Infinity/Math.atan", "-0", -Infinity)
320 testmath("Math.atan", "Number.POSITIVE_INFINITY", Math.PI/2)
321 testmath("Math.atan", "Number.NEGATIVE_INFINITY", -Math.PI/2)
322 testmath("Math.atan", "1", Math.PI/4)
323 testmath("Math.atan", "-1", -Math.PI/4)
325 testmath("Math.atan2", "Number.NaN,0", Number.NaN)
326 testmath("Math.atan2", "null, null", 0)
327 testmath("Math.atan2", "void 0, void 0", Number.NaN)
328 testmath("Math.atan2", "0,Number.NaN", Number.NaN)
329 testmath("Math.atan2", "1,0", Math.PI/2)
330 testmath("Math.atan2", "1,-0", Math.PI/2)
331 testmath("Math.atan2", "0,0.001", 0)
332 testmath("Math.atan2", "0,0", 0)
333 testmath("Math.atan2", "0,-0", Math.PI)
334 testmath("Math.atan2", "0, -1", Math.PI)
335 testmath("Math.atan2", "-0, 1", -0)
336 testmath("Infinity/Math.atan2", "-0,1", -Infinity)
337 testmath("Math.atan2", "-0,0", -0)
338 testmath("Math.atan2", "-0, -0", -Math.PI)
339 testmath("Math.atan2", "-0, -1", -Math.PI)
340 testmath("Math.atan2", "-1, 0", -Math.PI/2)
341 testmath("Math.atan2", "-1, -0", -Math.PI/2)
342 testmath("Math.atan2", "1, Number.POSITIVE_INFINITY", 0)
343 testmath("Math.atan2", "1, Number.NEGATIVE_INFINITY", Math.PI)
344 testmath("Math.atan2", "-1,Number.POSITIVE_INFINITY", -0)
345 testmath("Infinity/Math.atan2", "-1,Infinity", -Infinity)
346 testmath("Math.atan2", "-1,Number.NEGATIVE_INFINITY", -Math.PI)
347 testmath("Math.atan2", "Number.POSITIVE_INFINITY, 0", Math.PI/2)
348 testmath("Math.atan2", "Number.POSITIVE_INFINITY, 1", Math.PI/2)
349 testmath("Math.atan2", "Number.POSITIVE_INFINITY,-1", Math.PI/2)
350 testmath("Math.atan2", "Number.POSITIVE_INFINITY,-0", Math.PI/2)
351 testmath("Math.atan2", "Number.NEGATIVE_INFINITY, 0", -Math.PI/2)
352 testmath("Math.atan2", "Number.NEGATIVE_INFINITY,-0", -Math.PI/2)
353 testmath("Math.atan2", "Number.NEGATIVE_INFINITY, 1", -Math.PI/2)
354 testmath("Math.atan2", "Number.NEGATIVE_INFINITY,-1", -Math.PI/2)
355 testmath("Math.atan2", "Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY", Math.PI/4)
356 testmath("Math.atan2", "Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY", 3*Math.PI/4)
357 testmath("Math.atan2", "Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY", -Math.PI/4)
358 testmath("Math.atan2", "Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY", -3*Math.PI/4)
359 testmath("Math.atan2", "-1, 1", -Math.PI/4)
361 testmath("Math.ceil", "Number.NaN", Number.NaN)
362 testmath("Math.ceil", "null", 0)
363 testmath("Math.ceil", "void 0", Number.NaN)
364 testmath("Math.ceil", "'0'", 0)
365 testmath("Math.ceil", "'-0'", -0)
366 testmath("Infinity/Math.ceil", "'0'", Infinity)
367 testmath("Infinity/Math.ceil", "'-0'", -Infinity)
368 testmath("Math.ceil", "0", 0)
369 testmath("Math.ceil", "-0", -0)
370 testmath("Infinity/Math.ceil", "0", Infinity)
371 testmath("Infinity/Math.ceil", "-0", -Infinity)
372 testmath("Math.ceil", "Number.POSITIVE_INFINITY", Number.POSITIVE_INFINITY)
373 testmath("Math.ceil", "Number.NEGATIVE_INFINITY", Number.NEGATIVE_INFINITY)
374 testmath("Math.ceil", "-Number.MIN_VALUE", -0)
375 testmath("Infinity/Math.ceil", "-Number.MIN_VALUE", -Infinity)
376 testmath("Math.ceil", "1", 1)
377 testmath("Math.ceil", "-1", -1)
378 testmath("Math.ceil", "-0.9", -0)
379 testmath("Infinity/Math.ceil", "-0.9", -Infinity)
380 testmath("Math.ceil", "0.9", 1)
381 testmath("Math.ceil", "-1.1", -1)
382 testmath("Math.ceil", "1.1", 2)
383 testmath("Math.ceil", "Number.POSITIVE_INFINITY", -Math.floor(-Infinity))
384 testmath("Math.ceil", "Number.NEGATIVE_INFINITY", -Math.floor(Infinity))
385 testmath("Math.ceil", "-Number.MIN_VALUE", -Math.floor(Number.MIN_VALUE))
386 testmath("Math.ceil", "1", -Math.floor(-1))
387 testmath("Math.ceil", "-1", -Math.floor(1))
388 testmath("Math.ceil", "-0.9", -Math.floor(0.9))
389 testmath("Math.ceil", "0.9", -Math.floor(-0.9))
390 testmath("Math.ceil", "-1.1", -Math.floor(1.1))
391 testmath("Math.ceil", "1.1", -Math.floor(-1.1))
393 testmath("Math.cos", "void 0", Number.NaN)
394 testmath("Math.cos", "false", 1)
395 testmath("Math.cos", "null", 1)
396 testmath("Math.cos", "'0'", 1)
397 testmath("Math.cos", "\"Infinity\"", Number.NaN)
398 testmath("Math.cos", "'3.14159265359'", -1)
399 testmath("Math.cos", "Number.NaN", Number.NaN)
400 testmath("Math.cos", "0", 1)
401 testmath("Math.cos", "-0", 1)
402 testmath("Math.cos", "Number.POSITIVE_INFINITY", Number.NaN)
403 testmath("Math.cos", "Number.NEGATIVE_INFINITY", Number.NaN)
404 testmath("Math.cos", "0.7853981633974", 0.7071067811865)
405 testmath("Math.cos", "1.570796326795", 0)
406 testmath("Math.cos", "2.356194490192", -0.7071067811865)
407 testmath("Math.cos", "3.14159265359", -1)
408 testmath("Math.cos", "3.926990816987", -0.7071067811865)
409 testmath("Math.cos", "4.712388980385", 0)
410 testmath("Math.cos", "5.497787143782", 0.7071067811865)
411 testmath("Math.cos", "Math.PI*2", 1)
412 testmath("Math.cos", "Math.PI/4", Math.SQRT2/2)
413 testmath("Math.cos", "Math.PI/2", 0)
414 testmath("Math.cos", "3*Math.PI/4", -Math.SQRT2/2)
415 testmath("Math.cos", "Math.PI", -1)
416 testmath("Math.cos", "5*Math.PI/4", -Math.SQRT2/2)
417 testmath("Math.cos", "3*Math.PI/2", 0)
418 testmath("Math.cos", "7*Math.PI/4", Math.SQRT2/2)
419 testmath("Math.cos", "2*Math.PI", 1)
420 testmath("Math.cos", "-0.7853981633974", 0.7071067811865)
421 testmath("Math.cos", "-1.570796326795", 0)
422 testmath("Math.cos", "2.3561944901920", -.7071067811865)
423 testmath("Math.cos", "3.14159265359", -1)
424 testmath("Math.cos", "3.926990816987", -0.7071067811865)
425 testmath("Math.cos", "4.712388980385", 0)
426 testmath("Math.cos", "5.497787143782", 0.7071067811865)
427 testmath("Math.cos", "6.28318530718", 1)
428 testmath("Math.cos", "-Math.PI/4", Math.SQRT2/2)
429 testmath("Math.cos", "-Math.PI/2", 0)
430 testmath("Math.cos", "-3*Math.PI/4", -Math.SQRT2/2)
431 testmath("Math.cos", "-Math.PI", -1)
432 testmath("Math.cos", "-5*Math.PI/4", -Math.SQRT2/2)
433 testmath("Math.cos", "-3*Math.PI/2", 0)
434 testmath("Math.cos", "-7*Math.PI/4", Math.SQRT2/2)
435 testmath("Math.cos", "-Math.PI*2", 1)
437 testmath("Math.exp", "null", 1)
438 testmath("Math.exp", "void 0", Number.NaN)
439 testmath("Math.exp", "1", Math.E)
440 testmath("Math.exp", "true", Math.E)
441 testmath("Math.exp", "false", 1)
442 testmath("Math.exp", "'1'", Math.E)
443 testmath("Math.exp", "'0'", 1)
444 testmath("Math.exp", "Number.NaN", Number.NaN)
445 testmath("Math.exp", "0", 1)
446 testmath("Math.exp", "-0", 1)
447 testmath("Math.exp", "Number.POSITIVE_INFINITY", Number.POSITIVE_INFINITY)
448 testmath("Math.exp", "Number.NEGATIVE_INFINITY", 0)
450 testmath("Math.floor", "void 0", Number.NaN)
451 testmath("Math.floor", "null", 0)
452 testmath("Math.floor", "true", 1)
453 testmath("Math.floor", "false", 0)
454 testmath("Math.floor", "\"1.1\"", 1)
455 testmath("Math.floor", "\"-1.1\"", -2)
456 testmath("Math.floor", "\"0.1\"", 0)
457 testmath("Math.floor", "\"-0.1\"", -1)
458 testmath("Math.floor", "Number.NaN", Number.NaN)
459 testmath("Math.floor(Number.NaN) == -Math.ceil", "-Number.NaN", false)
460 testmath("Math.floor", "0", 0)
461 testmath("Math.floor(0) == -Math.ceil", "-0", true)
462 testmath("Math.floor", "-0", -0)
463 testmath("Infinity/Math.floor", "-0", -Infinity)
464 testmath("Math.floor(-0)== -Math.ceil", "0", true)
465 testmath("Math.floor", "Number.POSITIVE_INFINITY", Number.POSITIVE_INFINITY)
466 testmath("Math.floor(Number.POSITIVE_INFINITY) == -Math.ceil", "Number.NEGATIVE_INFINITY", true)
467 testmath("Math.floor", "Number.NEGATIVE_INFINITY", Number.NEGATIVE_INFINITY)
468 testmath("Math.floor(Number.NEGATIVE_INFINITY) == -Math.ceil", "Number.POSITIVE_INFINITY", true)
469 testmath("Math.floor", "0.0000001", 0)
470 testmath("Math.floor(0.0000001)==-Math.ceil", "-0.0000001", true)
471 testmath("Math.floor", "-0.0000001", -1)
472 testmath("Math.floor(-0.0000001)==-Math.ceil", "0.0000001", true)
474 testmath("Math.log", "void 0", Number.NaN)
475 testmath("Math.log", "null", Number.NEGATIVE_INFINITY)
476 testmath("Math.log", "true", 0)
477 testmath("Math.log", "false", -Infinity)
478 testmath("Math.log", "'0'", -Infinity)
479 testmath("Math.log", "'1'", 0)
480 testmath("Math.log", "\"Infinity\"", Infinity)
481 testmath("Math.log", "Number.NaN", Number.NaN)
482 testmath("Math.log", "-0.000001", Number.NaN)
483 testmath("Math.log", "-1", Number.NaN)
484 testmath("Math.log", "0", Number.NEGATIVE_INFINITY)
485 testmath("Math.log", "-0", Number.NEGATIVE_INFINITY)
486 testmath("Math.log", "1", 0)
487 testmath("Math.log", "Number.POSITIVE_INFINITY", Number.POSITIVE_INFINITY)
488 testmath("Math.log", "Number.NEGATIVE_INFINITY", Number.NaN)
490 testmath("Math.max", "void 0, 1", Number.NaN)
491 testmath("Math.max", "void 0, void 0", Number.NaN)
492 testmath("Math.max", "null, 1", 1)
493 testmath("Math.max", "-1, null", 0)
494 testmath("Math.max", "true,false", 1)
495 testmath("Math.max", "\"-99\",\"99\"", 99)
496 testmath("Math.max", "Number.NaN,Number.POSITIVE_INFINITY", Number.NaN)
497 testmath("Math.max", "Number.NaN, 0", Number.NaN)
498 testmath("Math.max", "\"a string\", 0", Number.NaN)
499 testmath("Math.max", "Number.NaN,1", Number.NaN)
500 testmath("Math.max", "\"a string\", Number.POSITIVE_INFINITY", Number.NaN)
501 testmath("Math.max", "Number.POSITIVE_INFINITY, Number.NaN", Number.NaN)
502 testmath("Math.max", "Number.NaN, Number.NaN", Number.NaN)
503 testmath("Math.max", "0,Number.NaN", Number.NaN)
504 testmath("Math.max", "1, Number.NaN", Number.NaN)
505 testmath("Math.max", "0,0", 0)
506 testmath("Math.max", "0,-0", 0)
507 testmath("Math.max", "-0,0", 0)
508 testmath("Math.max", "-0,-0", -0)
509 testmath("Infinity/Math.max", "-0,-0", -Infinity)
510 testmath("Math.max", "Number.POSITIVE_INFINITY, Number.MAX_VALUE", Number.POSITIVE_INFINITY)
511 testmath("Math.max", "Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY", Number.POSITIVE_INFINITY)
512 testmath("Math.max", "Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY", Number.NEGATIVE_INFINITY)
513 testmath("Math.max", "1,.99999999999999", 1)
514 testmath("Math.max", "-1,-.99999999999999", -.99999999999999)
516 testmath("Math.min", "void 0, 1", Number.NaN)
517 testmath("Math.min", "void 0, void 0", Number.NaN)
518 testmath("Math.min", "null, 1", 0)
519 testmath("Math.min", "-1, null", -1)
520 testmath("Math.min", "true,false", 0)
521 testmath("Math.min", "\"-99\",\"99\"", -99)
522 testmath("Math.min", "Number.NaN,0", Number.NaN)
523 testmath("Math.min", "Number.NaN,1", Number.NaN)
524 testmath("Math.min", "Number.NaN,-1", Number.NaN)
525 testmath("Math.min", "0,Number.NaN", Number.NaN)
526 testmath("Math.min", "1,Number.NaN", Number.NaN)
527 testmath("Math.min", "-1,Number.NaN", Number.NaN)
528 testmath("Math.min", "Number.NaN,Number.NaN", Number.NaN)
529 testmath("Math.min", "1,1.0000000001", 1)
530 testmath("Math.min", "1.0000000001,1", 1)
531 testmath("Math.min", "0,0", 0)
532 testmath("Math.min", "0,-0", -0)
533 testmath("Math.min", "-0,-0", -0)
534 testmath("Infinity/Math.min", "0,-0", -Infinity)
535 testmath("Infinity/Math.min", "-0,-0", -Infinity)
537 testmath("Math.pow", "null,null", 1)
538 testmath("Math.pow", "void 0, void 0", Number.NaN)
539 testmath("Math.pow", "true, false", 1)
540 testmath("Math.pow", "false,true", 0)
541 testmath("Math.pow", "'2','32'", 4294967296)
542 testmath("Math.pow", "1,Number.NaN", Number.NaN)
543 testmath("Math.pow", "0,Number.NaN", Number.NaN)
544 testmath("Math.pow", "Number.NaN,0", 1)
545 testmath("Math.pow", "Number.NaN,-0", 1)
546 testmath("Math.pow", "Number.NaN, 1", Number.NaN)
547 testmath("Math.pow", "Number.NaN, .5", Number.NaN)
548 testmath("Math.pow", "1.00000001, Number.POSITIVE_INFINITY", Number.POSITIVE_INFINITY)
549 testmath("Math.pow", "1.00000001, Number.NEGATIVE_INFINITY", 0)
550 testmath("Math.pow", "-1.00000001,Number.POSITIVE_INFINITY", Number.POSITIVE_INFINITY)
551 testmath("Math.pow", "-1.00000001,Number.NEGATIVE_INFINITY", 0)
552 testmath("Math.pow", "1, Number.POSITIVE_INFINITY", Number.NaN)
553 testmath("Math.pow", "1, Number.NEGATIVE_INFINITY", Number.NaN)
554 testmath("Math.pow", "-1, Number.POSITIVE_INFINITY", Number.NaN)
555 testmath("Math.pow", "-1, Number.NEGATIVE_INFINITY", Number.NaN)
556 testmath("Math.pow", ".0000000009, Number.POSITIVE_INFINITY", 0)
557 testmath("Math.pow", "-.0000000009, Number.POSITIVE_INFINITY", 0)
558 testmath("Math.pow", "-.0000000009, Number.NEGATIVE_INFINITY", Number.POSITIVE_INFINITY)
559 testmath("Math.pow", "Number.POSITIVE_INFINITY,.00000000001", Number.POSITIVE_INFINITY)
560 testmath("Math.pow", "Number.POSITIVE_INFINITY, 1", Number.POSITIVE_INFINITY)
561 testmath("Math.pow", "Number.POSITIVE_INFINITY, -.00000000001", 0)
562 testmath("Math.pow", "Number.POSITIVE_INFINITY, -1", 0)
563 testmath("Math.pow", "Number.NEGATIVE_INFINITY, 1", Number.NEGATIVE_INFINITY)
564 testmath("Math.pow", "Number.NEGATIVE_INFINITY, 333", Number.NEGATIVE_INFINITY)
565 testmath("Math.pow", "Number.POSITIVE_INFINITY, 2", Number.POSITIVE_INFINITY)
566 testmath("Math.pow", "Number.NEGATIVE_INFINITY, 666", Number.POSITIVE_INFINITY)
567 testmath("Math.pow", "Number.NEGATIVE_INFINITY, 0.5", Number.POSITIVE_INFINITY)
568 testmath("Math.pow", "Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY", Number.POSITIVE_INFINITY)
569 testmath("Math.pow", "Number.NEGATIVE_INFINITY, -1", -0)
570 testmath("Infinity/Math.pow", "Number.NEGATIVE_INFINITY, -1", -Infinity)
571 testmath("Math.pow", "Number.NEGATIVE_INFINITY, -3", -0)
572 testmath("Math.pow", "Number.NEGATIVE_INFINITY, -2", 0)
573 testmath("Math.pow", "Number.NEGATIVE_INFINITY,-0.5", 0)
574 testmath("Math.pow", "Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY", 0)
575 testmath("Math.pow", "0,1", 0)
576 testmath("Math.pow", "0,0", 1)
577 testmath("Math.pow", "1,0", 1)
578 testmath("Math.pow", "-1,0", 1)
579 testmath("Math.pow", "0,0.5", 0)
580 testmath("Math.pow", "0,1000", 0)
581 testmath("Math.pow", "0, Number.POSITIVE_INFINITY", 0)
582 testmath("Math.pow", "0, -1", Number.POSITIVE_INFINITY)
583 testmath("Math.pow", "0, -0.5", Number.POSITIVE_INFINITY)
584 testmath("Math.pow", "0, -1000", Number.POSITIVE_INFINITY)
585 testmath("Math.pow", "0, Number.NEGATIVE_INFINITY", Number.POSITIVE_INFINITY)
586 testmath("Math.pow", "-0, 1", -0)
587 testmath("Math.pow", "-0,3", -0)
588 testmath("Infinity/Math.pow", "-0, 1", -Infinity)
589 testmath("Infinity/Math.pow", "-0,3", -Infinity)
590 testmath("Math.pow", "-0,2", 0)
591 testmath("Math.pow", "-0, Number.POSITIVE_INFINITY", 0)
592 testmath("Math.pow", "-0, -1", Number.NEGATIVE_INFINITY)
593 testmath("Math.pow", "-0, -10001", Number.NEGATIVE_INFINITY)
594 testmath("Math.pow", "-0, -2", Number.POSITIVE_INFINITY)
595 testmath("Math.pow", "-0, 0.5", 0)
596 testmath("Math.pow", "-0, Number.POSITIVE_INFINITY", 0)
597 testmath("Math.pow", "-1, 0.5", Number.NaN)
598 testmath("Math.pow", "-1, Number.NaN", Number.NaN)
599 testmath("Math.pow", "-1, -0.5", Number.NaN)
601 testmath("Math.round", "0", 0)
602 testmath("Math.round", "void 0", Number.NaN)
603 testmath("Math.round", "true", 1)
604 testmath("Math.round", "false", 0)
605 testmath("Math.round", "'.99999'", 1)
606 testmath("Math.round", "'12345e-2'", 123)
607 testmath("Math.round", "Number.NaN", Number.NaN)
608 testmath("Math.round", "0", 0)
609 testmath("Math.round", "-0", -0)
610 testmath("Infinity/Math.round", "-0", -Infinity)
611 testmath("Math.round", "Number.POSITIVE_INFINITY", Number.POSITIVE_INFINITY)
612 testmath("Math.round", "Number.NEGATIVE_INFINITY", Number.NEGATIVE_INFINITY)
613 testmath("Math.round", "0.49", 0)
614 testmath("Math.round", "0.5", 1)
615 testmath("Math.round", "0.51", 1)
616 testmath("Math.round", "-0.49", -0)
617 testmath("Math.round", "-0.5", -0)
618 testmath("Infinity/Math.round", "-0.49", -Infinity)
619 testmath("Infinity/Math.round", "-0.5", -Infinity)
620 testmath("Math.round", "-0.51", -1)
621 testmath("Math.round", "3.5", 4)
622 testmath("Math.round", "-3", -3)
624 testmath("Math.sin", "null", 0)
625 testmath("Math.sin", "void 0", Number.NaN)
626 testmath("Math.sin", "false", 0)
627 testmath("Math.sin", "'2.356194490192'", 0.7071067811865)
628 testmath("Math.sin", "Number.NaN", Number.NaN)
629 testmath("Math.sin", "0", 0)
630 testmath("Math.sin", "-0", -0)
631 testmath("Math.sin", "Number.POSITIVE_INFINITY", Number.NaN)
632 testmath("Math.sin", "Number.NEGATIVE_INFINITY", Number.NaN)
633 testmath("Math.sin", "0.7853981633974", 0.7071067811865)
634 testmath("Math.sin", "1.570796326795", 1)
635 testmath("Math.sin", "2.356194490192", 0.7071067811865)
636 testmath("Math.sin", "3.14159265359", 0)
638 testmath("Math.sqrt", "void 0", Number.NaN)
639 testmath("Math.sqrt", "null", 0)
640 testmath("Math.sqrt", "1", 1)
641 testmath("Math.sqrt", "false", 0)
642 testmath("Math.sqrt", "'225'", 15)
643 testmath("Math.sqrt", "Number.NaN", Number.NaN)
644 testmath("Math.sqrt", "Number.NEGATIVE_INFINITY", Number.NaN)
645 testmath("Math.sqrt", "-1", Number.NaN)
646 testmath("Math.sqrt", "-0.5", Number.NaN)
647 testmath("Math.sqrt", "0", 0)
648 testmath("Math.sqrt", "-0", -0)
649 testmath("Infinity/Math.sqrt", "-0", -Infinity)
650 testmath("Math.sqrt", "Number.POSITIVE_INFINITY", Number.POSITIVE_INFINITY)
651 testmath("Math.sqrt", "1", 1)
652 testmath("Math.sqrt", "2", Math.SQRT2)
653 testmath("Math.sqrt", "0.5", Math.SQRT1_2)
654 testmath("Math.sqrt", "4", 2)
655 testmath("Math.sqrt", "9", 3)
656 testmath("Math.sqrt", "16", 4)
657 testmath("Math.sqrt", "25", 5)
658 testmath("Math.sqrt", "36", 6)
659 testmath("Math.sqrt", "49", 7)
660 testmath("Math.sqrt", "64", 8)
661 testmath("Math.sqrt", "256", 16)
662 testmath("Math.sqrt", "10000", 100)
663 testmath("Math.sqrt", "65536", 256)
664 testmath("Math.sqrt", "0.09", 0.3)
665 testmath("Math.sqrt", "0.01", 0.1)
666 testmath("Math.sqrt", "0.00000001", 0.0001)
668 testmath("Math.tan", "void 0", Number.NaN)
669 testmath("Math.tan", "null", 0)
670 testmath("Math.tan", "false", 0)
671 testmath("Math.tan", "Number.NaN", Number.NaN)
672 testmath("Math.tan", "0", 0)
673 testmath("Math.tan", "-0", -0)
674 testmath("Math.tan", "Number.POSITIVE_INFINITY", Number.NaN)
675 testmath("Math.tan", "Number.NEGATIVE_INFINITY", Number.NaN)
676 testmath("Math.tan", "Math.PI/4", 1)
677 testmath("Math.tan", "3*Math.PI/4", -1)
678 testmath("Math.tan", "Math.PI", -0)
679 testmath("Math.tan", "5*Math.PI/4", 1)
680 testmath("Math.tan", "7*Math.PI/4", -1)
681 testmath("Infinity/Math.tan", "-0", -Infinity)
683 jit(false);
685 /* Keep these at the end so that we can see the summary after the trace-debug spew. */
686 if (0) {
687 print("\npassed:", passes.length && passes.join(","));
688 print("\nFAILED:", fails.length && fails.join(","));
689 }