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