-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathbigint.jsdoc
More file actions
90 lines (68 loc) · 2.12 KB
/
Copy pathbigint.jsdoc
File metadata and controls
90 lines (68 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
BigInt : Object
An arbitrarily large integer value. Allows storing integers larger than what
%%/Number|Number%% allows. Use %%Number#Number_BigInt|Number(bigInt)%% to
convert a BigInt to a Number.
Primitive:
true
Spec:
https://tc39.es/ecma262/#sec-bigint-objects
Version:
ECMAScript 2020
----
BigInt(int : Number) : BigInt
Creates a BigInt for the specified number. **int** should be between
%%/Number#MIN_SAFE_INTEGER|Number.MIN_SAFE_INTEGER%% and
%%/Number#MIN_SAFE_INTEGER|Number.MAX_SAFE_INTEGER%%.
<example>
// The following are equivalent
const w = BigInt(15);
const x = 15n; // Decimal
const y = 0xFn; // Hex
const z = 0b1111n; // Binary
console.log(w + x);
</example>
Spec:
https://tc39.es/ecma262/#sec-bigint-constructor-number-value
----
BigInt(int : String) : BigInt
Converts the specified string to a BigInt. Allows constructing BigInts
larger than %%/Number|Number%%s.
<example>
// The following are equivalent
const x = BigInt('15');
const y = BigInt('0xF'); // Hex
const z = BigInt('0b1111'); // Binary
// The String constructor allows creating BigInts larger than Number allows
const a = BigInt('9999999999999999');
const b = BigInt(9999999999999999); // Exceeds Number.MAX_SAFE_INTEGER
const c = 9999999999999999n;
console.log(a);
console.log(b);
console.log(c);
</example>
Spec:
https://tc39.es/ecma262/#sec-bigint-constructor-number-value
----
prototype.asIntN(n : Number, bigInt : BigInt) : BigInt
Truncates **bigInt** to an **n**-bit signed integer.
<example>
console.log(BigInt.asIntN(16, 0x0001n));
console.log(BigInt.asIntN(16, 0x7FFFn));
console.log(BigInt.asIntN(16, 0x8000n));
console.log(BigInt.asIntN(16, 0xFFFFn));
console.log(BigInt.asIntN(16, 0x10000n));
</example>
Spec:
https://tc39.es/ecma262/#sec-bigint.asintn
----
prototype.asUintN(n : Number, bigInt : BigInt) : BigInt
Truncates **bigInt** to an **n**-bit unsigned integer.
<example>
console.log(BigInt.asUintN(16, 0x0001n));
console.log(BigInt.asUintN(16, 0x7FFFn));
console.log(BigInt.asUintN(16, 0x8000n));
console.log(BigInt.asUintN(16, 0xFFFFn));
console.log(BigInt.asUintN(16, 0x10000n));
</example>
Spec:
https://tc39.es/ecma262/#sec-bigint.asuintn