OLD | NEW |
(Empty) | |
| 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 |
| 4 // met: |
| 5 // |
| 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. |
| 15 // |
| 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. |
| 27 |
| 28 var x; |
| 29 |
| 30 // Converts a number to string respecting -0. |
| 31 function stringify(n) { |
| 32 if ((1 / n) === -Infinity) return "-0"; |
| 33 return String(n); |
| 34 } |
| 35 |
| 36 function f(expected, y) { |
| 37 function testEval(string, x, y) { |
| 38 var mulFunction = Function("x, y", "return " + string); |
| 39 return mulFunction(x, y); |
| 40 } |
| 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)); |
| 46 } |
| 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); |
| 56 } |
| 57 |
| 58 x = 0; |
| 59 f(0, 0); |
| 60 x = 1; |
| 61 f(0, 0); |
| 62 f(1, 1); |
| 63 x = 2; |
| 64 f(0, 0); |
| 65 f(2, 1); |
| 66 f(4, 2); |
| 67 x = 3; |
| 68 f(0, 0); |
| 69 f(3, 1); |
| 70 f(6, 2); |
| 71 f(9, 3); |
| 72 x = 4; |
| 73 f(0, 0); |
| 74 f(4, 1); |
| 75 f(8, 2); |
| 76 f(12, 3); |
| 77 f(16, 4); |
| 78 x = 5; |
| 79 f(0, 0); |
| 80 f(5, 1); |
| 81 f(10, 2); |
| 82 f(15, 3); |
| 83 f(20, 4); |
| 84 f(25, 5); |
| 85 x = 7; |
| 86 f(0, 0); |
| 87 f(7, 1); |
| 88 f(14, 2); |
| 89 f(21, 3); |
| 90 f(28, 4); |
| 91 f(35, 5); |
| 92 f(49, 7); |
| 93 x = 8; |
| 94 f(0, 0); |
| 95 f(8, 1); |
| 96 f(16, 2); |
| 97 f(24, 3); |
| 98 f(32, 4); |
| 99 f(40, 5); |
| 100 f(56, 7); |
| 101 f(64, 8); |
| 102 x = 9; |
| 103 f(0, 0); |
| 104 f(9, 1); |
| 105 f(18, 2); |
| 106 f(27, 3); |
| 107 f(36, 4); |
| 108 f(45, 5); |
| 109 f(63, 7); |
| 110 f(72, 8); |
| 111 f(81, 9); |
| 112 x = 15; |
| 113 f(0, 0); |
| 114 f(15, 1); |
| 115 f(30, 2); |
| 116 f(45, 3); |
| 117 f(60, 4); |
| 118 f(75, 5); |
| 119 f(105, 7); |
| 120 f(120, 8); |
| 121 f(135, 9); |
| 122 f(225, 15); |
| 123 x = 16; |
| 124 f(0, 0); |
| 125 f(16, 1); |
| 126 f(32, 2); |
| 127 f(48, 3); |
| 128 f(64, 4); |
| 129 f(80, 5); |
| 130 f(112, 7); |
| 131 f(128, 8); |
| 132 f(144, 9); |
| 133 f(240, 15); |
| 134 f(256, 16); |
| 135 x = 17; |
| 136 f(0, 0); |
| 137 f(17, 1); |
| 138 f(34, 2); |
| 139 f(51, 3); |
| 140 f(68, 4); |
| 141 f(85, 5); |
| 142 f(119, 7); |
| 143 f(136, 8); |
| 144 f(153, 9); |
| 145 f(255, 15); |
| 146 f(272, 16); |
| 147 f(289, 17); |
| 148 x = 31; |
| 149 f(0, 0); |
| 150 f(31, 1); |
| 151 f(62, 2); |
| 152 f(93, 3); |
| 153 f(124, 4); |
| 154 f(155, 5); |
| 155 f(217, 7); |
| 156 f(248, 8); |
| 157 f(279, 9); |
| 158 f(465, 15); |
| 159 f(496, 16); |
| 160 f(527, 17); |
| 161 f(961, 31); |
| 162 x = 32; |
| 163 f(0, 0); |
| 164 f(32, 1); |
| 165 f(64, 2); |
| 166 f(96, 3); |
| 167 f(128, 4); |
| 168 f(160, 5); |
| 169 f(224, 7); |
| 170 f(256, 8); |
| 171 f(288, 9); |
| 172 f(480, 15); |
| 173 f(512, 16); |
| 174 f(544, 17); |
| 175 f(992, 31); |
| 176 f(1024, 32); |
| 177 x = 33; |
| 178 f(0, 0); |
| 179 f(33, 1); |
| 180 f(66, 2); |
| 181 f(99, 3); |
| 182 f(132, 4); |
| 183 f(165, 5); |
| 184 f(231, 7); |
| 185 f(264, 8); |
| 186 f(297, 9); |
| 187 f(495, 15); |
| 188 f(528, 16); |
| 189 f(561, 17); |
| 190 f(1023, 31); |
| 191 f(1056, 32); |
| 192 f(1089, 33); |
| 193 x = 63; |
| 194 f(0, 0); |
| 195 f(63, 1); |
| 196 f(126, 2); |
| 197 f(189, 3); |
| 198 f(252, 4); |
| 199 f(315, 5); |
| 200 f(441, 7); |
| 201 f(504, 8); |
| 202 f(567, 9); |
| 203 f(945, 15); |
| 204 f(1008, 16); |
| 205 f(1071, 17); |
| 206 f(1953, 31); |
| 207 f(2016, 32); |
| 208 f(2079, 33); |
| 209 f(3969, 63); |
| 210 x = 64; |
| 211 f(0, 0); |
| 212 f(64, 1); |
| 213 f(128, 2); |
| 214 f(192, 3); |
| 215 f(256, 4); |
| 216 f(320, 5); |
| 217 f(448, 7); |
| 218 f(512, 8); |
| 219 f(576, 9); |
| 220 f(960, 15); |
| 221 f(1024, 16); |
| 222 f(1088, 17); |
| 223 f(1984, 31); |
| 224 f(2048, 32); |
| 225 f(2112, 33); |
| 226 f(4032, 63); |
| 227 f(4096, 64); |
| 228 x = 65; |
| 229 f(0, 0); |
| 230 f(65, 1); |
| 231 f(130, 2); |
| 232 f(195, 3); |
| 233 f(260, 4); |
| 234 f(325, 5); |
| 235 f(455, 7); |
| 236 f(520, 8); |
| 237 f(585, 9); |
| 238 f(975, 15); |
| 239 f(1040, 16); |
| 240 f(1105, 17); |
| 241 f(2015, 31); |
| 242 f(2080, 32); |
| 243 f(2145, 33); |
| 244 f(4095, 63); |
| 245 f(4160, 64); |
| 246 f(4225, 65); |
| 247 x = 127; |
| 248 f(0, 0); |
| 249 f(127, 1); |
| 250 f(254, 2); |
| 251 f(381, 3); |
| 252 f(508, 4); |
| 253 f(635, 5); |
| 254 f(889, 7); |
| 255 f(1016, 8); |
| 256 f(1143, 9); |
| 257 f(1905, 15); |
| 258 f(2032, 16); |
| 259 f(2159, 17); |
| 260 f(3937, 31); |
| 261 f(4064, 32); |
| 262 f(4191, 33); |
| 263 f(8001, 63); |
| 264 f(8128, 64); |
| 265 f(8255, 65); |
| 266 f(16129, 127); |
| 267 x = 128; |
| 268 f(0, 0); |
| 269 f(128, 1); |
| 270 f(256, 2); |
| 271 f(384, 3); |
| 272 f(512, 4); |
| 273 f(640, 5); |
| 274 f(896, 7); |
| 275 f(1024, 8); |
| 276 f(1152, 9); |
| 277 f(1920, 15); |
| 278 f(2048, 16); |
| 279 f(2176, 17); |
| 280 f(3968, 31); |
| 281 f(4096, 32); |
| 282 f(4224, 33); |
| 283 f(8064, 63); |
| 284 f(8192, 64); |
| 285 f(8320, 65); |
| 286 f(16256, 127); |
| 287 f(16384, 128); |
| 288 x = 129; |
| 289 f(0, 0); |
| 290 f(129, 1); |
| 291 f(258, 2); |
| 292 f(387, 3); |
| 293 f(516, 4); |
| 294 f(645, 5); |
| 295 f(903, 7); |
| 296 f(1032, 8); |
| 297 f(1161, 9); |
| 298 f(1935, 15); |
| 299 f(2064, 16); |
| 300 f(2193, 17); |
| 301 f(3999, 31); |
| 302 f(4128, 32); |
| 303 f(4257, 33); |
| 304 f(8127, 63); |
| 305 f(8256, 64); |
| 306 f(8385, 65); |
| 307 f(16383, 127); |
| 308 f(16512, 128); |
| 309 f(16641, 129); |
| 310 x = 255; |
| 311 f(0, 0); |
| 312 f(255, 1); |
| 313 f(510, 2); |
| 314 f(765, 3); |
| 315 f(1020, 4); |
| 316 f(1275, 5); |
| 317 f(1785, 7); |
| 318 f(2040, 8); |
| 319 f(2295, 9); |
| 320 f(3825, 15); |
| 321 f(4080, 16); |
| 322 f(4335, 17); |
| 323 f(7905, 31); |
| 324 f(8160, 32); |
| 325 f(8415, 33); |
| 326 f(16065, 63); |
| 327 f(16320, 64); |
| 328 f(16575, 65); |
| 329 f(32385, 127); |
| 330 f(32640, 128); |
| 331 f(32895, 129); |
| 332 f(65025, 255); |
| 333 x = 256; |
| 334 f(0, 0); |
| 335 f(256, 1); |
| 336 f(512, 2); |
| 337 f(768, 3); |
| 338 f(1024, 4); |
| 339 f(1280, 5); |
| 340 f(1792, 7); |
| 341 f(2048, 8); |
| 342 f(2304, 9); |
| 343 f(3840, 15); |
| 344 f(4096, 16); |
| 345 f(4352, 17); |
| 346 f(7936, 31); |
| 347 f(8192, 32); |
| 348 f(8448, 33); |
| 349 f(16128, 63); |
| 350 f(16384, 64); |
| 351 f(16640, 65); |
| 352 f(32512, 127); |
| 353 f(32768, 128); |
| 354 f(33024, 129); |
| 355 f(65280, 255); |
| 356 f(65536, 256); |
| 357 x = 257; |
| 358 f(0, 0); |
| 359 f(257, 1); |
| 360 f(514, 2); |
| 361 f(771, 3); |
| 362 f(1028, 4); |
| 363 f(1285, 5); |
| 364 f(1799, 7); |
| 365 f(2056, 8); |
| 366 f(2313, 9); |
| 367 f(3855, 15); |
| 368 f(4112, 16); |
| 369 f(4369, 17); |
| 370 f(7967, 31); |
| 371 f(8224, 32); |
| 372 f(8481, 33); |
| 373 f(16191, 63); |
| 374 f(16448, 64); |
| 375 f(16705, 65); |
| 376 f(32639, 127); |
| 377 f(32896, 128); |
| 378 f(33153, 129); |
| 379 f(65535, 255); |
| 380 f(65792, 256); |
| 381 f(66049, 257); |
| 382 x = 511; |
| 383 f(0, 0); |
| 384 f(511, 1); |
| 385 f(1022, 2); |
| 386 f(1533, 3); |
| 387 f(2044, 4); |
| 388 f(2555, 5); |
| 389 f(3577, 7); |
| 390 f(4088, 8); |
| 391 f(4599, 9); |
| 392 f(7665, 15); |
| 393 f(8176, 16); |
| 394 f(8687, 17); |
| 395 f(15841, 31); |
| 396 f(16352, 32); |
| 397 f(16863, 33); |
| 398 f(32193, 63); |
| 399 f(32704, 64); |
| 400 f(33215, 65); |
| 401 f(64897, 127); |
| 402 f(65408, 128); |
| 403 f(65919, 129); |
| 404 f(130305, 255); |
| 405 f(130816, 256); |
| 406 f(131327, 257); |
| 407 f(261121, 511); |
| 408 x = 512; |
| 409 f(0, 0); |
| 410 f(512, 1); |
| 411 f(1024, 2); |
| 412 f(1536, 3); |
| 413 f(2048, 4); |
| 414 f(2560, 5); |
| 415 f(3584, 7); |
| 416 f(4096, 8); |
| 417 f(4608, 9); |
| 418 f(7680, 15); |
| 419 f(8192, 16); |
| 420 f(8704, 17); |
| 421 f(15872, 31); |
| 422 f(16384, 32); |
| 423 f(16896, 33); |
| 424 f(32256, 63); |
| 425 f(32768, 64); |
| 426 f(33280, 65); |
| 427 f(65024, 127); |
| 428 f(65536, 128); |
| 429 f(66048, 129); |
| 430 f(130560, 255); |
| 431 f(131072, 256); |
| 432 f(131584, 257); |
| 433 f(261632, 511); |
| 434 f(262144, 512); |
| 435 x = 513; |
| 436 f(0, 0); |
| 437 f(513, 1); |
| 438 f(1026, 2); |
| 439 f(1539, 3); |
| 440 f(2052, 4); |
| 441 f(2565, 5); |
| 442 f(3591, 7); |
| 443 f(4104, 8); |
| 444 f(4617, 9); |
| 445 f(7695, 15); |
| 446 f(8208, 16); |
| 447 f(8721, 17); |
| 448 f(15903, 31); |
| 449 f(16416, 32); |
| 450 f(16929, 33); |
| 451 f(32319, 63); |
| 452 f(32832, 64); |
| 453 f(33345, 65); |
| 454 f(65151, 127); |
| 455 f(65664, 128); |
| 456 f(66177, 129); |
| 457 f(130815, 255); |
| 458 f(131328, 256); |
| 459 f(131841, 257); |
| 460 f(262143, 511); |
| 461 f(262656, 512); |
| 462 f(263169, 513); |
| 463 x = 1023; |
| 464 f(0, 0); |
| 465 f(1023, 1); |
| 466 f(2046, 2); |
| 467 f(3069, 3); |
| 468 f(4092, 4); |
| 469 f(5115, 5); |
| 470 f(7161, 7); |
| 471 f(8184, 8); |
| 472 f(9207, 9); |
| 473 f(15345, 15); |
| 474 f(16368, 16); |
| 475 f(17391, 17); |
| 476 f(31713, 31); |
| 477 f(32736, 32); |
| 478 f(33759, 33); |
| 479 f(64449, 63); |
| 480 f(65472, 64); |
| 481 f(66495, 65); |
| 482 f(129921, 127); |
| 483 f(130944, 128); |
| 484 f(131967, 129); |
| 485 f(260865, 255); |
| 486 f(261888, 256); |
| 487 f(262911, 257); |
| 488 f(522753, 511); |
| 489 f(523776, 512); |
| 490 f(524799, 513); |
| 491 f(1046529, 1023); |
OLD | NEW |