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 = 16385; |
| 59 f(0, 0); |
| 60 f(16385, 1); |
| 61 f(32770, 2); |
| 62 f(49155, 3); |
| 63 f(65540, 4); |
| 64 f(81925, 5); |
| 65 f(114695, 7); |
| 66 f(131080, 8); |
| 67 f(147465, 9); |
| 68 f(245775, 15); |
| 69 f(262160, 16); |
| 70 f(278545, 17); |
| 71 f(507935, 31); |
| 72 f(524320, 32); |
| 73 f(540705, 33); |
| 74 f(1032255, 63); |
| 75 f(1048640, 64); |
| 76 f(1065025, 65); |
| 77 f(2080895, 127); |
| 78 f(2097280, 128); |
| 79 f(2113665, 129); |
| 80 f(4178175, 255); |
| 81 f(4194560, 256); |
| 82 f(4210945, 257); |
| 83 f(8372735, 511); |
| 84 f(8389120, 512); |
| 85 f(8405505, 513); |
| 86 f(16761855, 1023); |
| 87 f(16778240, 1024); |
| 88 f(16794625, 1025); |
| 89 f(33540095, 2047); |
| 90 f(33556480, 2048); |
| 91 f(33572865, 2049); |
| 92 f(67096575, 4095); |
| 93 f(67112960, 4096); |
| 94 f(67129345, 4097); |
| 95 f(134209535, 8191); |
| 96 f(134225920, 8192); |
| 97 f(134242305, 8193); |
| 98 f(268435455, 16383); |
| 99 f(268451840, 16384); |
| 100 f(268468225, 16385); |
| 101 x = 32767; |
| 102 f(0, 0); |
| 103 f(32767, 1); |
| 104 f(65534, 2); |
| 105 f(98301, 3); |
| 106 f(131068, 4); |
| 107 f(163835, 5); |
| 108 f(229369, 7); |
| 109 f(262136, 8); |
| 110 f(294903, 9); |
| 111 f(491505, 15); |
| 112 f(524272, 16); |
| 113 f(557039, 17); |
| 114 f(1015777, 31); |
| 115 f(1048544, 32); |
| 116 f(1081311, 33); |
| 117 f(2064321, 63); |
| 118 f(2097088, 64); |
| 119 f(2129855, 65); |
| 120 f(4161409, 127); |
| 121 f(4194176, 128); |
| 122 f(4226943, 129); |
| 123 f(8355585, 255); |
| 124 f(8388352, 256); |
| 125 f(8421119, 257); |
| 126 f(16743937, 511); |
| 127 f(16776704, 512); |
| 128 f(16809471, 513); |
| 129 f(33520641, 1023); |
| 130 f(33553408, 1024); |
| 131 f(33586175, 1025); |
| 132 f(67074049, 2047); |
| 133 f(67106816, 2048); |
| 134 f(67139583, 2049); |
| 135 f(134180865, 4095); |
| 136 f(134213632, 4096); |
| 137 f(134246399, 4097); |
| 138 f(268394497, 8191); |
| 139 f(268427264, 8192); |
| 140 f(268460031, 8193); |
| 141 f(536821761, 16383); |
| 142 f(536854528, 16384); |
| 143 f(536887295, 16385); |
| 144 f(1073676289, 32767); |
| 145 x = 32768; |
| 146 f(0, 0); |
| 147 f(32768, 1); |
| 148 f(65536, 2); |
| 149 f(98304, 3); |
| 150 f(131072, 4); |
| 151 f(163840, 5); |
| 152 f(229376, 7); |
| 153 f(262144, 8); |
| 154 f(294912, 9); |
| 155 f(491520, 15); |
| 156 f(524288, 16); |
| 157 f(557056, 17); |
| 158 f(1015808, 31); |
| 159 f(1048576, 32); |
| 160 f(1081344, 33); |
| 161 f(2064384, 63); |
| 162 f(2097152, 64); |
| 163 f(2129920, 65); |
| 164 f(4161536, 127); |
| 165 f(4194304, 128); |
| 166 f(4227072, 129); |
| 167 f(8355840, 255); |
| 168 f(8388608, 256); |
| 169 f(8421376, 257); |
| 170 f(16744448, 511); |
| 171 f(16777216, 512); |
| 172 f(16809984, 513); |
| 173 f(33521664, 1023); |
| 174 f(33554432, 1024); |
| 175 f(33587200, 1025); |
| 176 f(67076096, 2047); |
| 177 f(67108864, 2048); |
| 178 f(67141632, 2049); |
| 179 f(134184960, 4095); |
| 180 f(134217728, 4096); |
| 181 f(134250496, 4097); |
| 182 f(268402688, 8191); |
| 183 f(268435456, 8192); |
| 184 f(268468224, 8193); |
| 185 f(536838144, 16383); |
| 186 f(536870912, 16384); |
| 187 f(536903680, 16385); |
| 188 f(1073709056, 32767); |
| 189 f(1073741824, 32768); |
| 190 x = 32769; |
| 191 f(0, 0); |
| 192 f(32769, 1); |
| 193 f(65538, 2); |
| 194 f(98307, 3); |
| 195 f(131076, 4); |
| 196 f(163845, 5); |
| 197 f(229383, 7); |
| 198 f(262152, 8); |
| 199 f(294921, 9); |
| 200 f(491535, 15); |
| 201 f(524304, 16); |
| 202 f(557073, 17); |
| 203 f(1015839, 31); |
| 204 f(1048608, 32); |
| 205 f(1081377, 33); |
| 206 f(2064447, 63); |
| 207 f(2097216, 64); |
| 208 f(2129985, 65); |
| 209 f(4161663, 127); |
| 210 f(4194432, 128); |
| 211 f(4227201, 129); |
| 212 f(8356095, 255); |
| 213 f(8388864, 256); |
| 214 f(8421633, 257); |
| 215 f(16744959, 511); |
| 216 f(16777728, 512); |
| 217 f(16810497, 513); |
| 218 f(33522687, 1023); |
| 219 f(33555456, 1024); |
| 220 f(33588225, 1025); |
| 221 f(67078143, 2047); |
| 222 f(67110912, 2048); |
| 223 f(67143681, 2049); |
| 224 f(134189055, 4095); |
| 225 f(134221824, 4096); |
| 226 f(134254593, 4097); |
| 227 f(268410879, 8191); |
| 228 f(268443648, 8192); |
| 229 f(268476417, 8193); |
| 230 f(536854527, 16383); |
| 231 f(536887296, 16384); |
| 232 f(536920065, 16385); |
| 233 f(1073741823, 32767); |
| 234 f(1073774592, 32768); |
| 235 f(1073807361, 32769); |
| 236 x = 65535; |
| 237 f(0, 0); |
| 238 f(65535, 1); |
| 239 f(131070, 2); |
| 240 f(196605, 3); |
| 241 f(262140, 4); |
| 242 f(327675, 5); |
| 243 f(458745, 7); |
| 244 f(524280, 8); |
| 245 f(589815, 9); |
| 246 f(983025, 15); |
| 247 f(1048560, 16); |
| 248 f(1114095, 17); |
| 249 f(2031585, 31); |
| 250 f(2097120, 32); |
| 251 f(2162655, 33); |
| 252 f(4128705, 63); |
| 253 f(4194240, 64); |
| 254 f(4259775, 65); |
| 255 f(8322945, 127); |
| 256 f(8388480, 128); |
| 257 f(8454015, 129); |
| 258 f(16711425, 255); |
| 259 f(16776960, 256); |
| 260 f(16842495, 257); |
| 261 f(33488385, 511); |
| 262 f(33553920, 512); |
| 263 f(33619455, 513); |
| 264 f(67042305, 1023); |
| 265 f(67107840, 1024); |
| 266 f(67173375, 1025); |
| 267 f(134150145, 2047); |
| 268 f(134215680, 2048); |
| 269 f(134281215, 2049); |
| 270 f(268365825, 4095); |
| 271 f(268431360, 4096); |
| 272 f(268496895, 4097); |
| 273 f(536797185, 8191); |
| 274 f(536862720, 8192); |
| 275 f(536928255, 8193); |
| 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); |
| 283 x = 65536; |
| 284 f(0, 0); |
| 285 f(65536, 1); |
| 286 f(131072, 2); |
| 287 f(196608, 3); |
| 288 f(262144, 4); |
| 289 f(327680, 5); |
| 290 f(458752, 7); |
| 291 f(524288, 8); |
| 292 f(589824, 9); |
| 293 f(983040, 15); |
| 294 f(1048576, 16); |
| 295 f(1114112, 17); |
| 296 f(2031616, 31); |
| 297 f(2097152, 32); |
| 298 f(2162688, 33); |
| 299 f(4128768, 63); |
| 300 f(4194304, 64); |
| 301 f(4259840, 65); |
| 302 f(8323072, 127); |
| 303 f(8388608, 128); |
| 304 f(8454144, 129); |
| 305 f(16711680, 255); |
| 306 f(16777216, 256); |
| 307 f(16842752, 257); |
| 308 f(33488896, 511); |
| 309 f(33554432, 512); |
| 310 f(33619968, 513); |
| 311 f(67043328, 1023); |
| 312 f(67108864, 1024); |
| 313 f(67174400, 1025); |
| 314 f(134152192, 2047); |
| 315 f(134217728, 2048); |
| 316 f(134283264, 2049); |
| 317 f(268369920, 4095); |
| 318 f(268435456, 4096); |
| 319 f(268500992, 4097); |
| 320 f(536805376, 8191); |
| 321 f(536870912, 8192); |
| 322 f(536936448, 8193); |
| 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); |
| 331 x = 65537; |
| 332 f(0, 0); |
| 333 f(65537, 1); |
| 334 f(131074, 2); |
| 335 f(196611, 3); |
| 336 f(262148, 4); |
| 337 f(327685, 5); |
| 338 f(458759, 7); |
| 339 f(524296, 8); |
| 340 f(589833, 9); |
| 341 f(983055, 15); |
| 342 f(1048592, 16); |
| 343 f(1114129, 17); |
| 344 f(2031647, 31); |
| 345 f(2097184, 32); |
| 346 f(2162721, 33); |
| 347 f(4128831, 63); |
| 348 f(4194368, 64); |
| 349 f(4259905, 65); |
| 350 f(8323199, 127); |
| 351 f(8388736, 128); |
| 352 f(8454273, 129); |
| 353 f(16711935, 255); |
| 354 f(16777472, 256); |
| 355 f(16843009, 257); |
| 356 f(33489407, 511); |
| 357 f(33554944, 512); |
| 358 f(33620481, 513); |
| 359 f(67044351, 1023); |
| 360 f(67109888, 1024); |
| 361 f(67175425, 1025); |
| 362 f(134154239, 2047); |
| 363 f(134219776, 2048); |
| 364 f(134285313, 2049); |
| 365 f(268374015, 4095); |
| 366 f(268439552, 4096); |
| 367 f(268505089, 4097); |
| 368 f(536813567, 8191); |
| 369 f(536879104, 8192); |
| 370 f(536944641, 8193); |
| 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); |
| 380 x = 131071; |
| 381 f(0, 0); |
| 382 f(131071, 1); |
| 383 f(262142, 2); |
| 384 f(393213, 3); |
| 385 f(524284, 4); |
| 386 f(655355, 5); |
| 387 f(917497, 7); |
| 388 f(1048568, 8); |
| 389 f(1179639, 9); |
| 390 f(1966065, 15); |
| 391 f(2097136, 16); |
| 392 f(2228207, 17); |
| 393 f(4063201, 31); |
| 394 f(4194272, 32); |
| 395 f(4325343, 33); |
| 396 f(8257473, 63); |
| 397 f(8388544, 64); |
| 398 f(8519615, 65); |
| 399 f(16646017, 127); |
| 400 f(16777088, 128); |
| 401 f(16908159, 129); |
| 402 f(33423105, 255); |
| 403 f(33554176, 256); |
| 404 f(33685247, 257); |
| 405 f(66977281, 511); |
| 406 f(67108352, 512); |
| 407 f(67239423, 513); |
| 408 f(134085633, 1023); |
| 409 f(134216704, 1024); |
| 410 f(134347775, 1025); |
| 411 f(268302337, 2047); |
| 412 f(268433408, 2048); |
| 413 f(268564479, 2049); |
| 414 f(536735745, 4095); |
| 415 f(536866816, 4096); |
| 416 f(536997887, 4097); |
| 417 f(1073602561, 8191); |
| 418 f(1073733632, 8192); |
| 419 f(1073864703, 8193); |
| 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); |
| 430 x = 131072; |
| 431 f(0, 0); |
| 432 f(131072, 1); |
| 433 f(262144, 2); |
| 434 f(393216, 3); |
| 435 f(524288, 4); |
| 436 f(655360, 5); |
| 437 f(917504, 7); |
| 438 f(1048576, 8); |
| 439 f(1179648, 9); |
| 440 f(1966080, 15); |
| 441 f(2097152, 16); |
| 442 f(2228224, 17); |
| 443 f(4063232, 31); |
| 444 f(4194304, 32); |
| 445 f(4325376, 33); |
| 446 f(8257536, 63); |
| 447 f(8388608, 64); |
| 448 f(8519680, 65); |
| 449 f(16646144, 127); |
| 450 f(16777216, 128); |
| 451 f(16908288, 129); |
| 452 f(33423360, 255); |
| 453 f(33554432, 256); |
| 454 f(33685504, 257); |
| 455 f(66977792, 511); |
| 456 f(67108864, 512); |
| 457 f(67239936, 513); |
| 458 f(134086656, 1023); |
| 459 f(134217728, 1024); |
| 460 f(134348800, 1025); |
| 461 f(268304384, 2047); |
| 462 f(268435456, 2048); |
| 463 f(268566528, 2049); |
| 464 f(536739840, 4095); |
| 465 f(536870912, 4096); |
| 466 f(537001984, 4097); |
| 467 f(1073610752, 8191); |
| 468 f(1073741824, 8192); |
| 469 f(1073872896, 8193); |
| 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); |
| 481 x = 131073; |
| 482 f(0, 0); |
| 483 f(131073, 1); |
| 484 f(262146, 2); |
| 485 f(393219, 3); |
| 486 f(524292, 4); |
| 487 f(655365, 5); |
| 488 f(917511, 7); |
| 489 f(1048584, 8); |
| 490 f(1179657, 9); |
| 491 f(1966095, 15); |
| 492 f(2097168, 16); |
| 493 f(2228241, 17); |
| 494 f(4063263, 31); |
| 495 f(4194336, 32); |
| 496 f(4325409, 33); |
| 497 f(8257599, 63); |
| 498 f(8388672, 64); |
| 499 f(8519745, 65); |
| 500 f(16646271, 127); |
| 501 f(16777344, 128); |
| 502 f(16908417, 129); |
| 503 f(33423615, 255); |
| 504 f(33554688, 256); |
| 505 f(33685761, 257); |
| 506 f(66978303, 511); |
| 507 f(67109376, 512); |
| 508 f(67240449, 513); |
| 509 f(134087679, 1023); |
| 510 f(134218752, 1024); |
| 511 f(134349825, 1025); |
| 512 f(268306431, 2047); |
| 513 f(268437504, 2048); |
| 514 f(268568577, 2049); |
| 515 f(536743935, 4095); |
| 516 f(536875008, 4096); |
| 517 f(537006081, 4097); |
| 518 f(1073618943, 8191); |
| 519 f(1073750016, 8192); |
| 520 f(1073881089, 8193); |
| 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); |
OLD | NEW |