[JSC] Do not use asArrayModes() with Structures because it discards TypedArray inform...
[WebKit-https.git] / JSTests / stress / big-int-multiplication.js
1 //@ runBigIntEnabled
2
3 // Copyright (C) 2017 Robin Templeton. All rights reserved.
4 // This code is governed by the BSD license found in the LICENSE file.
5
6 assert = {
7     sameValue: function (input, expected, message) {
8     if (input !== expected)
9         throw new Error(message);
10     }
11 };
12
13 function testMul(x, y, z) {
14     assert.sameValue(x * y, z, x + " * " + y + " = " + z);
15     assert.sameValue(y * x, z, y + " * " + x + " = " + z);
16 }
17
18 testMul(0xFEDCBA9876543210n, 0xFEDCBA9876543210n, 0xFDBAC097C8DC5ACCDEEC6CD7A44A4100n);
19 testMul(0xFEDCBA9876543210n, 0xFEDCBA98n, 0xFDBAC097530ECA86541D5980n);
20 testMul(0xFEDCBA9876543210n, 0x1234n, 0x121F49F49F49F49F4B40n);
21 testMul(0xFEDCBA9876543210n, 0x3n, 0x2FC962FC962FC9630n);
22 testMul(0xFEDCBA9876543210n, 0x2n, 0x1FDB97530ECA86420n);
23 testMul(0xFEDCBA9876543210n, 0x1n, 0xFEDCBA9876543210n);
24 testMul(0xFEDCBA9876543210n, 0x0n, 0x0n);
25 testMul(0xFEDCBA9876543210n, BigInt("-1"), BigInt("-18364758544493064720"));
26 testMul(0xFEDCBA9876543210n, BigInt("-2"), BigInt("-36729517088986129440"));
27 testMul(0xFEDCBA9876543210n, BigInt("-3"), BigInt("-55094275633479194160"));
28 testMul(0xFEDCBA9876543210n, BigInt("-4660"), BigInt("-85579774817337681595200"));
29 testMul(0xFEDCBA9876543210n, BigInt("-4275878551"), BigInt("-78525477154691874604502820720"));
30 testMul(0xFEDCBA987654320Fn, 0xFEDCBA987654320Fn, 0xFDBAC097C8DC5ACAE132F7A6B7A1DCE1n);
31 testMul(0xFEDCBA987654320Fn, 0xFEDCBA97n, 0xFDBAC09654320FECDEEC6CD9n);
32 testMul(0xFEDCBA987654320Fn, 0x3n, 0x2FC962FC962FC962Dn);
33 testMul(0xFEDCBA987654320Fn, 0x2n, 0x1FDB97530ECA8641En);
34 testMul(0xFEDCBA987654320Fn, 0x1n, 0xFEDCBA987654320Fn);
35 testMul(0xFEDCBA987654320Fn, 0x0n, 0x0n);
36 testMul(0xFEDCBA987654320Fn, BigInt("-1"), BigInt("-18364758544493064719"));
37 testMul(0xFEDCBA987654320Fn, BigInt("-2"), BigInt("-36729517088986129438"));
38 testMul(0xFEDCBA987654320Fn, BigInt("-3"), BigInt("-55094275633479194157"));
39 testMul(0xFEDCBA987654320Fn, BigInt("-4275878551"), BigInt("-78525477154691874600226942169"));
40 testMul(0xFEDCBA987654320Fn, BigInt("-18364758544493064720"), BigInt("-337264356397531028976608289633615613680"));
41 testMul(0xFEDCBA98n, 0xFEDCBA98n, 0xFDBAC096DD413A40n);
42 testMul(0xFEDCBA98n, 0x1234n, 0x121F49F496E0n);
43 testMul(0xFEDCBA98n, 0x3n, 0x2FC962FC8n);
44 testMul(0xFEDCBA98n, 0x2n, 0x1FDB97530n);
45 testMul(0xFEDCBA98n, 0x1n, 0xFEDCBA98n);
46 testMul(0xFEDCBA98n, 0x0n, 0x0n);
47 testMul(0xFEDCBA98n, BigInt("-1"), BigInt("-4275878552"));
48 testMul(0xFEDCBA98n, BigInt("-2"), BigInt("-8551757104"));
49 testMul(0xFEDCBA98n, BigInt("-3"), BigInt("-12827635656"));
50 testMul(0xFEDCBA98n, BigInt("-4275878551"), BigInt("-18283137387177738152"));
51 testMul(0xFEDCBA98n, BigInt("-18364758544493064720"), BigInt("-78525477173056633148995885440"));
52 testMul(0x3n, 0x3n, 0x9n);
53 testMul(0x3n, 0x2n, 0x6n);
54 testMul(0x3n, 0x1n, 0x3n);
55 testMul(0x3n, 0x0n, 0x0n);
56 testMul(0x3n, BigInt("-1"), BigInt("-3"));
57 testMul(0x3n, BigInt("-2"), BigInt("-6"));
58 testMul(0x3n, BigInt("-3"), BigInt("-9"));
59 testMul(0x3n, BigInt("-4660"), BigInt("-13980"));
60 testMul(0x3n, BigInt("-4275878552"), BigInt("-12827635656"));
61 testMul(0x3n, BigInt("-18364758544493064720"), BigInt("-55094275633479194160"));
62 testMul(0x0n, 0x0n, 0x0n);
63 testMul(0x0n, BigInt("-1"), 0x0n);
64 testMul(0x0n, BigInt("-2"), 0x0n);
65 testMul(0x0n, BigInt("-3"), 0x0n);
66 testMul(0x0n, BigInt("-4275878551"), 0x0n);
67 testMul(0x0n, BigInt("-18364758544493064719"), 0x0n);
68 testMul(BigInt("-1"), BigInt("-1"), 0x1n);
69 testMul(BigInt("-1"), BigInt("-2"), 0x2n);
70 testMul(BigInt("-1"), BigInt("-3"), 0x3n);
71 testMul(BigInt("-1"), BigInt("-4660"), 0x1234n);
72 testMul(BigInt("-1"), BigInt("-4275878551"), 0xFEDCBA97n);
73 testMul(BigInt("-1"), BigInt("-4275878552"), 0xFEDCBA98n);
74 testMul(BigInt("-1"), BigInt("-18364758544493064719"), 0xFEDCBA987654320Fn);
75 testMul(BigInt("-1"), BigInt("-18364758544493064720"), 0xFEDCBA9876543210n);
76 testMul(BigInt("-3"), BigInt("-3"), 0x9n);
77 testMul(BigInt("-3"), BigInt("-4660"), 0x369Cn);
78 testMul(BigInt("-3"), BigInt("-4275878551"), 0x2FC962FC5n);
79 testMul(BigInt("-3"), BigInt("-4275878552"), 0x2FC962FC8n);
80 testMul(BigInt("-3"), BigInt("-18364758544493064719"), 0x2FC962FC962FC962Dn);
81 testMul(BigInt("-3"), BigInt("-18364758544493064720"), 0x2FC962FC962FC9630n);
82 testMul(BigInt("-18364758544493064720"), BigInt("-18364758544493064720"), 0xFDBAC097C8DC5ACCDEEC6CD7A44A4100n);
83