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 = 536870913; |
| 59 f(0, 0); |
| 60 f(536870913, 1); |
| 61 f(1073741826, 2); |
| 62 f(1610612739, 3); |
| 63 f(2147483652, 4); |
| 64 f(2684354565, 5); |
| 65 f(3758096391, 7); |
| 66 f(4294967304, 8); |
| 67 f(4831838217, 9); |
| 68 f(8053063695, 15); |
| 69 f(8589934608, 16); |
| 70 f(9126805521, 17); |
| 71 f(16642998303, 31); |
| 72 f(17179869216, 32); |
| 73 f(17716740129, 33); |
| 74 f(33822867519, 63); |
| 75 f(34359738432, 64); |
| 76 f(34896609345, 65); |
| 77 f(68182605951, 127); |
| 78 f(68719476864, 128); |
| 79 f(69256347777, 129); |
| 80 f(136902082815, 255); |
| 81 f(137438953728, 256); |
| 82 f(137975824641, 257); |
| 83 f(274341036543, 511); |
| 84 f(274877907456, 512); |
| 85 f(275414778369, 513); |
| 86 f(549218943999, 1023); |
| 87 f(549755814912, 1024); |
| 88 f(550292685825, 1025); |
| 89 f(1098974758911, 2047); |
| 90 f(1099511629824, 2048); |
| 91 f(1100048500737, 2049); |
| 92 f(2198486388735, 4095); |
| 93 f(2199023259648, 4096); |
| 94 f(2199560130561, 4097); |
| 95 f(4397509648383, 8191); |
| 96 f(4398046519296, 8192); |
| 97 f(4398583390209, 8193); |
| 98 f(8795556167679, 16383); |
| 99 f(8796093038592, 16384); |
| 100 f(8796629909505, 16385); |
| 101 f(17591649206271, 32767); |
| 102 f(17592186077184, 32768); |
| 103 f(17592722948097, 32769); |
| 104 f(35183835283455, 65535); |
| 105 f(35184372154368, 65536); |
| 106 f(35184909025281, 65537); |
| 107 f(70368207437823, 131071); |
| 108 f(70368744308736, 131072); |
| 109 f(70369281179649, 131073); |
| 110 f(140736951746559, 262143); |
| 111 f(140737488617472, 262144); |
| 112 f(140738025488385, 262145); |
| 113 f(281474440364031, 524287); |
| 114 f(281474977234944, 524288); |
| 115 f(281475514105857, 524289); |
| 116 f(562949417598975, 1048575); |
| 117 f(562949954469888, 1048576); |
| 118 f(562950491340801, 1048577); |
| 119 f(1125899372068863, 2097151); |
| 120 f(1125899908939776, 2097152); |
| 121 f(1125900445810689, 2097153); |
| 122 x = 1073741823; |
| 123 f(0, 0); |
| 124 f(1073741823, 1); |
| 125 f(2147483646, 2); |
| 126 f(3221225469, 3); |
| 127 f(4294967292, 4); |
| 128 f(5368709115, 5); |
| 129 f(7516192761, 7); |
| 130 f(8589934584, 8); |
| 131 f(9663676407, 9); |
| 132 f(16106127345, 15); |
| 133 f(17179869168, 16); |
| 134 f(18253610991, 17); |
| 135 f(33285996513, 31); |
| 136 f(34359738336, 32); |
| 137 f(35433480159, 33); |
| 138 f(67645734849, 63); |
| 139 f(68719476672, 64); |
| 140 f(69793218495, 65); |
| 141 f(136365211521, 127); |
| 142 f(137438953344, 128); |
| 143 f(138512695167, 129); |
| 144 f(273804164865, 255); |
| 145 f(274877906688, 256); |
| 146 f(275951648511, 257); |
| 147 f(548682071553, 511); |
| 148 f(549755813376, 512); |
| 149 f(550829555199, 513); |
| 150 f(1098437884929, 1023); |
| 151 f(1099511626752, 1024); |
| 152 f(1100585368575, 1025); |
| 153 f(2197949511681, 2047); |
| 154 f(2199023253504, 2048); |
| 155 f(2200096995327, 2049); |
| 156 f(4396972765185, 4095); |
| 157 f(4398046507008, 4096); |
| 158 f(4399120248831, 4097); |
| 159 f(8795019272193, 8191); |
| 160 f(8796093014016, 8192); |
| 161 f(8797166755839, 8193); |
| 162 f(17591112286209, 16383); |
| 163 f(17592186028032, 16384); |
| 164 f(17593259769855, 16385); |
| 165 f(35183298314241, 32767); |
| 166 f(35184372056064, 32768); |
| 167 f(35185445797887, 32769); |
| 168 f(70367670370305, 65535); |
| 169 f(70368744112128, 65536); |
| 170 f(70369817853951, 65537); |
| 171 f(140736414482433, 131071); |
| 172 f(140737488224256, 131072); |
| 173 f(140738561966079, 131073); |
| 174 f(281473902706689, 262143); |
| 175 f(281474976448512, 262144); |
| 176 f(281476050190335, 262145); |
| 177 f(562948879155201, 524287); |
| 178 f(562949952897024, 524288); |
| 179 f(562951026638847, 524289); |
| 180 f(1125898832052225, 1048575); |
| 181 f(1125899905794048, 1048576); |
| 182 f(1125900979535871, 1048577); |
| 183 x = 1073741824; |
| 184 f(0, 0); |
| 185 f(1073741824, 1); |
| 186 f(2147483648, 2); |
| 187 f(3221225472, 3); |
| 188 f(4294967296, 4); |
| 189 f(5368709120, 5); |
| 190 f(7516192768, 7); |
| 191 f(8589934592, 8); |
| 192 f(9663676416, 9); |
| 193 f(16106127360, 15); |
| 194 f(17179869184, 16); |
| 195 f(18253611008, 17); |
| 196 f(33285996544, 31); |
| 197 f(34359738368, 32); |
| 198 f(35433480192, 33); |
| 199 f(67645734912, 63); |
| 200 f(68719476736, 64); |
| 201 f(69793218560, 65); |
| 202 f(136365211648, 127); |
| 203 f(137438953472, 128); |
| 204 f(138512695296, 129); |
| 205 f(273804165120, 255); |
| 206 f(274877906944, 256); |
| 207 f(275951648768, 257); |
| 208 f(548682072064, 511); |
| 209 f(549755813888, 512); |
| 210 f(550829555712, 513); |
| 211 f(1098437885952, 1023); |
| 212 f(1099511627776, 1024); |
| 213 f(1100585369600, 1025); |
| 214 f(2197949513728, 2047); |
| 215 f(2199023255552, 2048); |
| 216 f(2200096997376, 2049); |
| 217 f(4396972769280, 4095); |
| 218 f(4398046511104, 4096); |
| 219 f(4399120252928, 4097); |
| 220 f(8795019280384, 8191); |
| 221 f(8796093022208, 8192); |
| 222 f(8797166764032, 8193); |
| 223 f(17591112302592, 16383); |
| 224 f(17592186044416, 16384); |
| 225 f(17593259786240, 16385); |
| 226 f(35183298347008, 32767); |
| 227 f(35184372088832, 32768); |
| 228 f(35185445830656, 32769); |
| 229 f(70367670435840, 65535); |
| 230 f(70368744177664, 65536); |
| 231 f(70369817919488, 65537); |
| 232 f(140736414613504, 131071); |
| 233 f(140737488355328, 131072); |
| 234 f(140738562097152, 131073); |
| 235 f(281473902968832, 262143); |
| 236 f(281474976710656, 262144); |
| 237 f(281476050452480, 262145); |
| 238 f(562948879679488, 524287); |
| 239 f(562949953421312, 524288); |
| 240 f(562951027163136, 524289); |
| 241 f(1125898833100800, 1048575); |
| 242 f(1125899906842624, 1048576); |
| 243 f(1125900980584448, 1048577); |
| 244 x = 1073741825; |
| 245 f(0, 0); |
| 246 f(1073741825, 1); |
| 247 f(2147483650, 2); |
| 248 f(3221225475, 3); |
| 249 f(4294967300, 4); |
| 250 f(5368709125, 5); |
| 251 f(7516192775, 7); |
| 252 f(8589934600, 8); |
| 253 f(9663676425, 9); |
| 254 f(16106127375, 15); |
| 255 f(17179869200, 16); |
| 256 f(18253611025, 17); |
| 257 f(33285996575, 31); |
| 258 f(34359738400, 32); |
| 259 f(35433480225, 33); |
| 260 f(67645734975, 63); |
| 261 f(68719476800, 64); |
| 262 f(69793218625, 65); |
| 263 f(136365211775, 127); |
| 264 f(137438953600, 128); |
| 265 f(138512695425, 129); |
| 266 f(273804165375, 255); |
| 267 f(274877907200, 256); |
| 268 f(275951649025, 257); |
| 269 f(548682072575, 511); |
| 270 f(549755814400, 512); |
| 271 f(550829556225, 513); |
| 272 f(1098437886975, 1023); |
| 273 f(1099511628800, 1024); |
| 274 f(1100585370625, 1025); |
| 275 f(2197949515775, 2047); |
| 276 f(2199023257600, 2048); |
| 277 f(2200096999425, 2049); |
| 278 f(4396972773375, 4095); |
| 279 f(4398046515200, 4096); |
| 280 f(4399120257025, 4097); |
| 281 f(8795019288575, 8191); |
| 282 f(8796093030400, 8192); |
| 283 f(8797166772225, 8193); |
| 284 f(17591112318975, 16383); |
| 285 f(17592186060800, 16384); |
| 286 f(17593259802625, 16385); |
| 287 f(35183298379775, 32767); |
| 288 f(35184372121600, 32768); |
| 289 f(35185445863425, 32769); |
| 290 f(70367670501375, 65535); |
| 291 f(70368744243200, 65536); |
| 292 f(70369817985025, 65537); |
| 293 f(140736414744575, 131071); |
| 294 f(140737488486400, 131072); |
| 295 f(140738562228225, 131073); |
| 296 f(281473903230975, 262143); |
| 297 f(281474976972800, 262144); |
| 298 f(281476050714625, 262145); |
| 299 f(562948880203775, 524287); |
| 300 f(562949953945600, 524288); |
| 301 f(562951027687425, 524289); |
| 302 f(1125898834149375, 1048575); |
| 303 f(1125899907891200, 1048576); |
| 304 f(1125900981633025, 1048577); |
| 305 x = 2147483647; |
| 306 f(0, 0); |
| 307 f(2147483647, 1); |
| 308 f(4294967294, 2); |
| 309 f(6442450941, 3); |
| 310 f(8589934588, 4); |
| 311 f(10737418235, 5); |
| 312 f(15032385529, 7); |
| 313 f(17179869176, 8); |
| 314 f(19327352823, 9); |
| 315 f(32212254705, 15); |
| 316 f(34359738352, 16); |
| 317 f(36507221999, 17); |
| 318 f(66571993057, 31); |
| 319 f(68719476704, 32); |
| 320 f(70866960351, 33); |
| 321 f(135291469761, 63); |
| 322 f(137438953408, 64); |
| 323 f(139586437055, 65); |
| 324 f(272730423169, 127); |
| 325 f(274877906816, 128); |
| 326 f(277025390463, 129); |
| 327 f(547608329985, 255); |
| 328 f(549755813632, 256); |
| 329 f(551903297279, 257); |
| 330 f(1097364143617, 511); |
| 331 f(1099511627264, 512); |
| 332 f(1101659110911, 513); |
| 333 f(2196875770881, 1023); |
| 334 f(2199023254528, 1024); |
| 335 f(2201170738175, 1025); |
| 336 f(4395899025409, 2047); |
| 337 f(4398046509056, 2048); |
| 338 f(4400193992703, 2049); |
| 339 f(8793945534465, 4095); |
| 340 f(8796093018112, 4096); |
| 341 f(8798240501759, 4097); |
| 342 f(17590038552577, 8191); |
| 343 f(17592186036224, 8192); |
| 344 f(17594333519871, 8193); |
| 345 f(35182224588801, 16383); |
| 346 f(35184372072448, 16384); |
| 347 f(35186519556095, 16385); |
| 348 f(70366596661249, 32767); |
| 349 f(70368744144896, 32768); |
| 350 f(70370891628543, 32769); |
| 351 f(140735340806145, 65535); |
| 352 f(140737488289792, 65536); |
| 353 f(140739635773439, 65537); |
| 354 f(281472829095937, 131071); |
| 355 f(281474976579584, 131072); |
| 356 f(281477124063231, 131073); |
| 357 f(562947805675521, 262143); |
| 358 f(562949953159168, 262144); |
| 359 f(562952100642815, 262145); |
| 360 f(1125897758834689, 524287); |
| 361 f(1125899906318336, 524288); |
| 362 f(1125902053801983, 524289); |
| 363 x = 2147483648; |
| 364 f(0, 0); |
| 365 f(2147483648, 1); |
| 366 f(4294967296, 2); |
| 367 f(6442450944, 3); |
| 368 f(8589934592, 4); |
| 369 f(10737418240, 5); |
| 370 f(15032385536, 7); |
| 371 f(17179869184, 8); |
| 372 f(19327352832, 9); |
| 373 f(32212254720, 15); |
| 374 f(34359738368, 16); |
| 375 f(36507222016, 17); |
| 376 f(66571993088, 31); |
| 377 f(68719476736, 32); |
| 378 f(70866960384, 33); |
| 379 f(135291469824, 63); |
| 380 f(137438953472, 64); |
| 381 f(139586437120, 65); |
| 382 f(272730423296, 127); |
| 383 f(274877906944, 128); |
| 384 f(277025390592, 129); |
| 385 f(547608330240, 255); |
| 386 f(549755813888, 256); |
| 387 f(551903297536, 257); |
| 388 f(1097364144128, 511); |
| 389 f(1099511627776, 512); |
| 390 f(1101659111424, 513); |
| 391 f(2196875771904, 1023); |
| 392 f(2199023255552, 1024); |
| 393 f(2201170739200, 1025); |
| 394 f(4395899027456, 2047); |
| 395 f(4398046511104, 2048); |
| 396 f(4400193994752, 2049); |
| 397 f(8793945538560, 4095); |
| 398 f(8796093022208, 4096); |
| 399 f(8798240505856, 4097); |
| 400 f(17590038560768, 8191); |
| 401 f(17592186044416, 8192); |
| 402 f(17594333528064, 8193); |
| 403 f(35182224605184, 16383); |
| 404 f(35184372088832, 16384); |
| 405 f(35186519572480, 16385); |
| 406 f(70366596694016, 32767); |
| 407 f(70368744177664, 32768); |
| 408 f(70370891661312, 32769); |
| 409 f(140735340871680, 65535); |
| 410 f(140737488355328, 65536); |
| 411 f(140739635838976, 65537); |
| 412 f(281472829227008, 131071); |
| 413 f(281474976710656, 131072); |
| 414 f(281477124194304, 131073); |
| 415 f(562947805937664, 262143); |
| 416 f(562949953421312, 262144); |
| 417 f(562952100904960, 262145); |
| 418 f(1125897759358976, 524287); |
| 419 f(1125899906842624, 524288); |
| 420 f(1125902054326272, 524289); |
| 421 x = 2147483649; |
| 422 f(0, 0); |
| 423 f(2147483649, 1); |
| 424 f(4294967298, 2); |
| 425 f(6442450947, 3); |
| 426 f(8589934596, 4); |
| 427 f(10737418245, 5); |
| 428 f(15032385543, 7); |
| 429 f(17179869192, 8); |
| 430 f(19327352841, 9); |
| 431 f(32212254735, 15); |
| 432 f(34359738384, 16); |
| 433 f(36507222033, 17); |
| 434 f(66571993119, 31); |
| 435 f(68719476768, 32); |
| 436 f(70866960417, 33); |
| 437 f(135291469887, 63); |
| 438 f(137438953536, 64); |
| 439 f(139586437185, 65); |
| 440 f(272730423423, 127); |
| 441 f(274877907072, 128); |
| 442 f(277025390721, 129); |
| 443 f(547608330495, 255); |
| 444 f(549755814144, 256); |
| 445 f(551903297793, 257); |
| 446 f(1097364144639, 511); |
| 447 f(1099511628288, 512); |
| 448 f(1101659111937, 513); |
| 449 f(2196875772927, 1023); |
| 450 f(2199023256576, 1024); |
| 451 f(2201170740225, 1025); |
| 452 f(4395899029503, 2047); |
| 453 f(4398046513152, 2048); |
| 454 f(4400193996801, 2049); |
| 455 f(8793945542655, 4095); |
| 456 f(8796093026304, 4096); |
| 457 f(8798240509953, 4097); |
| 458 f(17590038568959, 8191); |
| 459 f(17592186052608, 8192); |
| 460 f(17594333536257, 8193); |
| 461 f(35182224621567, 16383); |
| 462 f(35184372105216, 16384); |
| 463 f(35186519588865, 16385); |
| 464 f(70366596726783, 32767); |
| 465 f(70368744210432, 32768); |
| 466 f(70370891694081, 32769); |
| 467 f(140735340937215, 65535); |
| 468 f(140737488420864, 65536); |
| 469 f(140739635904513, 65537); |
| 470 f(281472829358079, 131071); |
| 471 f(281474976841728, 131072); |
| 472 f(281477124325377, 131073); |
| 473 f(562947806199807, 262143); |
| 474 f(562949953683456, 262144); |
| 475 f(562952101167105, 262145); |
| 476 f(1125897759883263, 524287); |
| 477 f(1125899907366912, 524288); |
| 478 f(1125902054850561, 524289); |
| 479 x = 4294967295; |
| 480 f(0, 0); |
| 481 f(4294967295, 1); |
| 482 f(8589934590, 2); |
| 483 f(12884901885, 3); |
| 484 f(17179869180, 4); |
| 485 f(21474836475, 5); |
| 486 f(30064771065, 7); |
| 487 f(34359738360, 8); |
| 488 f(38654705655, 9); |
| 489 f(64424509425, 15); |
| 490 f(68719476720, 16); |
| 491 f(73014444015, 17); |
| 492 f(133143986145, 31); |
| 493 f(137438953440, 32); |
| 494 f(141733920735, 33); |
| 495 f(270582939585, 63); |
| 496 f(274877906880, 64); |
| 497 f(279172874175, 65); |
| 498 f(545460846465, 127); |
| 499 f(549755813760, 128); |
| 500 f(554050781055, 129); |
| 501 f(1095216660225, 255); |
| 502 f(1099511627520, 256); |
| 503 f(1103806594815, 257); |
| 504 f(2194728287745, 511); |
| 505 f(2199023255040, 512); |
| 506 f(2203318222335, 513); |
| 507 f(4393751542785, 1023); |
| 508 f(4398046510080, 1024); |
| 509 f(4402341477375, 1025); |
| 510 f(8791798052865, 2047); |
| 511 f(8796093020160, 2048); |
| 512 f(8800387987455, 2049); |
| 513 f(17587891073025, 4095); |
| 514 f(17592186040320, 4096); |
| 515 f(17596481007615, 4097); |
| 516 f(35180077113345, 8191); |
| 517 f(35184372080640, 8192); |
| 518 f(35188667047935, 8193); |
| 519 f(70364449193985, 16383); |
| 520 f(70368744161280, 16384); |
| 521 f(70373039128575, 16385); |
| 522 f(140733193355265, 32767); |
| 523 f(140737488322560, 32768); |
| 524 f(140741783289855, 32769); |
| 525 f(281470681677825, 65535); |
| 526 f(281474976645120, 65536); |
| 527 f(281479271612415, 65537); |
| 528 f(562945658322945, 131071); |
| 529 f(562949953290240, 131072); |
| 530 f(562954248257535, 131073); |
| 531 f(1125895611613185, 262143); |
| 532 f(1125899906580480, 262144); |
| 533 f(1125904201547775, 262145); |
OLD | NEW |