1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // Converts a number to string respecting -0.
31 function stringify(n) {
32 if ((1 / n) === -Infinity) return "-0";
36 function f(expected, y) {
37 function testEval(string, x, y) {
38 var mulFunction = Function("x, y", "return " + string);
39 return mulFunction(x, y);
41 function mulTest(expected, x, y) {
42 assertEquals(expected, x * y);
43 assertEquals(expected, testEval(stringify(x) + " * y", x, y));
44 assertEquals(expected, testEval("x * " + stringify(y), x, y));
45 assertEquals(expected, testEval(stringify(x) + " * " + stringify(y), x, y));
47 mulTest(expected, x, y);
48 mulTest(-expected, -x, y);
49 mulTest(-expected, x, -y);
50 mulTest(expected, -x, -y);
51 if (x === y) return; // Symmetric cases not necessary.
52 mulTest(expected, y, x);
53 mulTest(-expected, -y, x);
54 mulTest(-expected, y, -x);
55 mulTest(expected, -y, -x);
144 f(1073676289, 32767);
188 f(1073709056, 32767);
189 f(1073741824, 32768);
233 f(1073741823, 32767);
234 f(1073774592, 32768);
235 f(1073807361, 32769);
276 f(1073659905, 16383);
277 f(1073725440, 16384);
278 f(1073790975, 16385);
279 f(2147385345, 32767);
280 f(2147450880, 32768);
281 f(2147516415, 32769);
282 f(4294836225, 65535);
323 f(1073676288, 16383);
324 f(1073741824, 16384);
325 f(1073807360, 16385);
326 f(2147418112, 32767);
327 f(2147483648, 32768);
328 f(2147549184, 32769);
329 f(4294901760, 65535);
330 f(4294967296, 65536);
371 f(1073692671, 16383);
372 f(1073758208, 16384);
373 f(1073823745, 16385);
374 f(2147450879, 32767);
375 f(2147516416, 32768);
376 f(2147581953, 32769);
377 f(4294967295, 65535);
378 f(4295032832, 65536);
379 f(4295098369, 65537);
420 f(2147336193, 16383);
421 f(2147467264, 16384);
422 f(2147598335, 16385);
423 f(4294803457, 32767);
424 f(4294934528, 32768);
425 f(4295065599, 32769);
426 f(8589737985, 65535);
427 f(8589869056, 65536);
428 f(8590000127, 65537);
429 f(17179607041, 131071);
470 f(2147352576, 16383);
471 f(2147483648, 16384);
472 f(2147614720, 16385);
473 f(4294836224, 32767);
474 f(4294967296, 32768);
475 f(4295098368, 32769);
476 f(8589803520, 65535);
477 f(8589934592, 65536);
478 f(8590065664, 65537);
479 f(17179738112, 131071);
480 f(17179869184, 131072);
521 f(2147368959, 16383);
522 f(2147500032, 16384);
523 f(2147631105, 16385);
524 f(4294868991, 32767);
525 f(4295000064, 32768);
526 f(4295131137, 32769);
527 f(8589869055, 65535);
528 f(8590000128, 65536);
529 f(8590131201, 65537);
530 f(17179869183, 131071);
531 f(17180000256, 131072);
532 f(17180131329, 131073);