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);
100 f(4295213055, 16385);
101 f(8589639681, 32767);
102 f(8589901824, 32768);
103 f(8590163967, 32769);
104 f(17179541505, 65535);
105 f(17179803648, 65536);
106 f(17180065791, 65537);
107 f(34359345153, 131071);
108 f(34359607296, 131072);
109 f(34359869439, 131073);
110 f(68718952449, 262143);
151 f(4294705152, 16383);
152 f(4294967296, 16384);
153 f(4295229440, 16385);
154 f(8589672448, 32767);
155 f(8589934592, 32768);
156 f(8590196736, 32769);
157 f(17179607040, 65535);
158 f(17179869184, 65536);
159 f(17180131328, 65537);
160 f(34359476224, 131071);
161 f(34359738368, 131072);
162 f(34360000512, 131073);
163 f(68719214592, 262143);
164 f(68719476736, 262144);
205 f(4294721535, 16383);
206 f(4294983680, 16384);
207 f(4295245825, 16385);
208 f(8589705215, 32767);
209 f(8589967360, 32768);
210 f(8590229505, 32769);
211 f(17179672575, 65535);
212 f(17179934720, 65536);
213 f(17180196865, 65537);
214 f(34359607295, 131071);
215 f(34359869440, 131072);
216 f(34360131585, 131073);
217 f(68719476735, 262143);
218 f(68719738880, 262144);
219 f(68720001025, 262145);
260 f(8589393921, 16383);
261 f(8589918208, 16384);
262 f(8590442495, 16385);
263 f(17179312129, 32767);
264 f(17179836416, 32768);
265 f(17180360703, 32769);
266 f(34359148545, 65535);
267 f(34359672832, 65536);
268 f(34360197119, 65537);
269 f(68718821377, 131071);
270 f(68719345664, 131072);
271 f(68719869951, 131073);
272 f(137438167041, 262143);
273 f(137438691328, 262144);
274 f(137439215615, 262145);
275 f(274876858369, 524287);
316 f(8589410304, 16383);
317 f(8589934592, 16384);
318 f(8590458880, 16385);
319 f(17179344896, 32767);
320 f(17179869184, 32768);
321 f(17180393472, 32769);
322 f(34359214080, 65535);
323 f(34359738368, 65536);
324 f(34360262656, 65537);
325 f(68718952448, 131071);
326 f(68719476736, 131072);
327 f(68720001024, 131073);
328 f(137438429184, 262143);
329 f(137438953472, 262144);
330 f(137439477760, 262145);
331 f(274877382656, 524287);
332 f(274877906944, 524288);
373 f(8589426687, 16383);
374 f(8589950976, 16384);
375 f(8590475265, 16385);
376 f(17179377663, 32767);
377 f(17179901952, 32768);
378 f(17180426241, 32769);
379 f(34359279615, 65535);
380 f(34359803904, 65536);
381 f(34360328193, 65537);
382 f(68719083519, 131071);
383 f(68719607808, 131072);
384 f(68720132097, 131073);
385 f(137438691327, 262143);
386 f(137439215616, 262144);
387 f(137439739905, 262145);
388 f(274877906943, 524287);
389 f(274878431232, 524288);
390 f(274878955521, 524289);
431 f(17178804225, 16383);
432 f(17179852800, 16384);
433 f(17180901375, 16385);
434 f(34358657025, 32767);
435 f(34359705600, 32768);
436 f(34360754175, 32769);
437 f(68718362625, 65535);
438 f(68719411200, 65536);
439 f(68720459775, 65537);
440 f(137437773825, 131071);
441 f(137438822400, 131072);
442 f(137439870975, 131073);
443 f(274876596225, 262143);
444 f(274877644800, 262144);
445 f(274878693375, 262145);
446 f(549754241025, 524287);
447 f(549755289600, 524288);
448 f(549756338175, 524289);
449 f(1099509530625, 1048575);
490 f(17178820608, 16383);
491 f(17179869184, 16384);
492 f(17180917760, 16385);
493 f(34358689792, 32767);
494 f(34359738368, 32768);
495 f(34360786944, 32769);
496 f(68718428160, 65535);
497 f(68719476736, 65536);
498 f(68720525312, 65537);
499 f(137437904896, 131071);
500 f(137438953472, 131072);
501 f(137440002048, 131073);
502 f(274876858368, 262143);
503 f(274877906944, 262144);
504 f(274878955520, 262145);
505 f(549754765312, 524287);
506 f(549755813888, 524288);
507 f(549756862464, 524289);
508 f(1099510579200, 1048575);
509 f(1099511627776, 1048576);