Debian Codegraph @

js/src/tests/non262/Intl/NumberFormat/bigint-int64.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
2
3 // Ensure the int64_t optimization when formatting a BigInt value works correctly by testing with
4 // various integers around the (u)int[32,64] limits.
5
6 const limits = {
7 int32: {
8 min: -0x80000000n,
9 max: 0x7FFFFFFFn,
10 },
11 uint32: {
12 min: 0n,
13 max: 0xFFFFFFFFn
14 },
15 int64: {
16 min: -0x8000000000000000n,
17 max: 0x7FFFFFFFFFFFFFFFn,
18 },
19 uint64: {
20 min: 0n,
21 max: 0xFFFFFFFFFFFFFFFFn
22 },
23 };
24
25 const nf = new Intl.NumberFormat("en", {useGrouping: false});
26
27 const diff = 10n;
28
29 for (const int of Object.values(limits)) {
30 for (let i = -diff; i <= diff; ++i) {
31 let n = int.min + i;
32 assertEq(nf.format(n), n.toString());
33
34 let m = int.max + i;
35 assertEq(nf.format(m), m.toString());
36 }
37 }
38
39 if (typeof reportCompare === "function")
40 reportCompare(true, true);