-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathspec.html
145 lines (133 loc) · 5.73 KB
/
spec.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<pre class=metadata>
title: ES BigInt Math (2025)
status: proposal
stage: 1
location: https://github.com/tc39/proposal-bigint-math
copyright: false
contributors: J. S. Choi
</pre>
<emu-intro id=introduction>
<h1>Introduction</h1>
<p>This is the formal specification for a proposed extension
of the `BigInt` JavaScript global object with further operations.
It modifies the original <a
href=https://tc39.es/ecma262/multipage/>ECMAScript specification</a> with
several new or revised clauses. See <a
href=https://github.com/tc39/proposal-bigint-math/blob/main/README.md>the proposal's
explainer</a> for the proposal's background, motivation, and usage examples.</p>
</emu-intro>
<emu-clause id="sec-properties-of-the-bigint-constructor">
<h1>Properties of the BigInt Constructor</h1>
<p>The BigInt constructor:</p>
<ul>
<li>has a [[Prototype]] internal slot whose value is %Function.prototype%.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-bigint.abs">
<h1><ins>BigInt.abs ( _x_ )</ins></h1>
<p>This function returns the absolute value of _x_ as a BigInt; the result has the same magnitude as _x_ but has positive sign.</p>
<p>It performs the following steps when called:</p>
<emu-alg>
1. Let _n_ be ? ToBigInt(_x_).
1. Return the BigInt value that represents abs(ℝ(_x_)).
</emu-alg>
</emu-clause>
<emu-clause id="sec-bigint.asintn">
<h1>BigInt.asIntN ( _bits_, _bigint_ )</h1>
<p>This function performs the following steps when called:</p>
<emu-alg>
1. Set _bits_ to ? ToIndex(_bits_).
1. Set _bigint_ to ? ToBigInt(_bigint_).
1. Let _mod_ be ℝ(_bigint_) modulo 2<sup>_bits_</sup>.
1. If _mod_ ≥ 2<sup>_bits_ - 1</sup>, return ℤ(_mod_ - 2<sup>_bits_</sup>); otherwise, return ℤ(_mod_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-bigint.asuintn">
<h1>BigInt.asUintN ( _bits_, _bigint_ )</h1>
<p>This function performs the following steps when called:</p>
<emu-alg>
1. Set _bits_ to ? ToIndex(_bits_).
1. Set _bigint_ to ? ToBigInt(_bigint_).
1. Return ℤ(ℝ(_bigint_) modulo 2<sup>_bits_</sup>).
</emu-alg>
</emu-clause>
<emu-clause id="sec-bigint.cbrt">
<h1><ins>BigInt.cbrt ( _x_ )</ins></h1>
<p>This function returns the cube root of _x_ as a BigInt.</p>
<p>It performs the following steps when called:</p>
<emu-alg>
1. Let _n_ be ? ToBigInt(_x_).
1. Let _root_ be the cube root of ℝ(_n_).
1. Return ℤ(truncate(_root_)).
</emu-alg>
</emu-clause>
<emu-clause id="sec-bigint.max">
<h1><ins>BigInt.max ( _firstArg_, ..._restArgs_ )</ins></h1>
<p>Given one or more arguments, this function calls ToBigInt on each of the arguments and returns the largest of the resulting values.</p>
<p>It performs the following steps when called:</p>
<emu-alg>
1. Let _firstCoerced_ be ? ToBigInt(_firstArg_).
1. Let _restCoerced_ be a new empty List.
1. For each element _arg_ of _restArgs_, do
1. Let _n_ be ? ToBigInt(_arg_).
1. Append _n_ to _restCoerced_.
1. Let _highest_ be _firstCoerced_.
1. For each element _number_ of _restCoerced_, do
1. If _number_ > _highest_, set _highest_ to _number_.
1. Return _highest_.
</emu-alg>
<p>The *"length"* property of this function is *2*<sub>𝔽</sub>.</p>
</emu-clause>
<emu-clause id="sec-bigint.min">
<h1><ins>BigInt.min ( _firstArg_, ..._restArgs_ )</ins></h1>
<p>Given one or more arguments, this function calls ToBigInt on each of the arguments and returns the smallest of the resulting values.</p>
<p>It performs the following steps when called:</p>
<emu-alg>
1. Let _firstCoerced_ be ? ToBigInt(_firstArg_).
1. Let _restCoerced_ be a new empty List.
1. For each element _arg_ of _restArgs_, do
1. Let _n_ be ? ToBigInt(_arg_).
1. Append _n_ to _restCoerced_.
1. Let _lowest_ be _firstCoerced_.
1. For each element _number_ of _restCoerced_, do
1. If _number_ < _lowest_, set _lowest_ to _number_.
1. Return _lowest_.
</emu-alg>
<p>The *"length"* property of this function is *2*<sub>𝔽</sub>.</p>
</emu-clause>
<emu-clause id="sec-bigint.pow">
<h1><ins>BigInt.pow ( _base_, _exponent_ )</ins></h1>
<p>This function performs the following steps when called:</p>
<emu-alg>
1. Set _base_ to ? ToBigInt(_base_).
1. Set _exponent_ to ? ToBigInt(_exponent_).
1. Return Number::exponentiate(_base_, _exponent_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-bigint.prototype">
<h1>BigInt.prototype</h1>
<p>The initial value of `BigInt.prototype` is the BigInt prototype object.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.</p>
</emu-clause>
<emu-clause id="sec-bigint.sign">
<h1><ins>BigInt.sign ( _x_ )</ins></h1>
<p>This function returns the sign of _x_ as a BigInt, indicating whether _x_ is positive, negative, or zero.</p>
<p>It performs the following steps when called:</p>
<emu-alg>
1. Let _n_ be ? ToBigInt(_x_).
1. If _n_ is *0*<sub>ℤ</sub>, return _n_.
1. If _n_ < *0*<sub>ℤ</sub>, return *-1*<sub>ℤ</sub>.
1. Return *1*<sub>ℤ</sub>.</emu-alg>
</emu-clause>
<emu-clause id="sec-bigint.sqrt">
<h1><ins>BigInt.sqrt ( _x_ )</ins></h1>
<p>This function returns the square root of _x_ as a BigInt.</p>
<p>It performs the following steps when called:</p>
<emu-alg>
1. Let _n_ be ? ToBigInt(_x_).
1. If _n_ < *0*<sub>ℤ</sub>, throw a *RangeError* exception.
1. Let _root_ be the square root of ℝ(_n_).
1. Return ℤ(truncate(_root_)).
</emu-alg>
</emu-clause>
</emu-clause>