@bsv/sdk 1.5.3 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/primitives/AESGCM.js +113 -137
- package/dist/cjs/src/primitives/AESGCM.js.map +1 -1
- package/dist/cjs/src/primitives/BigNumber.js +1019 -3947
- package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
- package/dist/cjs/src/primitives/K256.js +53 -37
- package/dist/cjs/src/primitives/K256.js.map +1 -1
- package/dist/cjs/src/primitives/Mersenne.js +16 -21
- package/dist/cjs/src/primitives/Mersenne.js.map +1 -1
- package/dist/cjs/src/primitives/MontgomoryMethod.js.map +1 -1
- package/dist/cjs/src/primitives/utils.js +27 -17
- package/dist/cjs/src/primitives/utils.js.map +1 -1
- package/dist/cjs/src/script/Spend.js +618 -858
- package/dist/cjs/src/script/Spend.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/primitives/AESGCM.js +112 -137
- package/dist/esm/src/primitives/AESGCM.js.map +1 -1
- package/dist/esm/src/primitives/BigNumber.js +1011 -3969
- package/dist/esm/src/primitives/BigNumber.js.map +1 -1
- package/dist/esm/src/primitives/K256.js +53 -37
- package/dist/esm/src/primitives/K256.js.map +1 -1
- package/dist/esm/src/primitives/Mersenne.js +16 -21
- package/dist/esm/src/primitives/Mersenne.js.map +1 -1
- package/dist/esm/src/primitives/MontgomoryMethod.js.map +1 -1
- package/dist/esm/src/primitives/utils.js +29 -17
- package/dist/esm/src/primitives/utils.js.map +1 -1
- package/dist/esm/src/script/Spend.js +618 -857
- package/dist/esm/src/script/Spend.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/primitives/AESGCM.d.ts.map +1 -1
- package/dist/types/src/primitives/BigNumber.d.ts +238 -1705
- package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
- package/dist/types/src/primitives/K256.d.ts.map +1 -1
- package/dist/types/src/primitives/Mersenne.d.ts +2 -2
- package/dist/types/src/primitives/Mersenne.d.ts.map +1 -1
- package/dist/types/src/primitives/utils.d.ts +2 -0
- package/dist/types/src/primitives/utils.d.ts.map +1 -1
- package/dist/types/src/script/Spend.d.ts +11 -1
- package/dist/types/src/script/Spend.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/performance.md +70 -0
- package/docs/primitives.md +262 -3049
- package/package.json +1 -1
- package/src/auth/__tests/Peer.test.ts +38 -23
- package/src/auth/certificates/__tests/MasterCertificate.test.ts +27 -20
- package/src/auth/certificates/__tests/VerifiableCertificate.test.ts +24 -24
- package/src/primitives/AESGCM.ts +118 -164
- package/src/primitives/BigNumber.ts +867 -4180
- package/src/primitives/K256.ts +57 -37
- package/src/primitives/Mersenne.ts +16 -20
- package/src/primitives/MontgomoryMethod.ts +2 -2
- package/src/primitives/__tests/ReductionContext.test.ts +6 -1
- package/src/primitives/utils.ts +28 -17
- package/src/script/Spend.ts +634 -1309
- package/src/transaction/__tests/Transaction.test.ts +14 -16
- package/src/transaction/__tests/Transaction.benchmarks.test.ts +0 -237
package/docs/primitives.md
CHANGED
|
@@ -64,105 +64,150 @@ export default class BigNumber {
|
|
|
64
64
|
static readonly groupSizes: number[]
|
|
65
65
|
static readonly groupBases: number[]
|
|
66
66
|
static readonly wordSize: number = 26;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
public red: ReductionContext | null;
|
|
68
|
+
public get negative(): number
|
|
69
|
+
public set negative(val: number)
|
|
70
|
+
public get words(): number[]
|
|
71
|
+
public set words(newWords: number[])
|
|
72
|
+
public get length(): number
|
|
71
73
|
static isBN(num: any): boolean
|
|
72
74
|
static max(left: BigNumber, right: BigNumber): BigNumber
|
|
73
75
|
static min(left: BigNumber, right: BigNumber): BigNumber
|
|
74
|
-
constructor(number: number | string | number[] = 0, base: number | "be" | "le" | "hex" = 10, endian: "be" | "le" = "be")
|
|
76
|
+
constructor(number: number | string | number[] | bigint | undefined = 0, base: number | "be" | "le" | "hex" = 10, endian: "be" | "le" = "be")
|
|
75
77
|
copy(dest: BigNumber): void
|
|
76
78
|
static move(dest: BigNumber, src: BigNumber): void
|
|
77
79
|
clone(): BigNumber
|
|
78
80
|
expand(size: number): this
|
|
79
81
|
strip(): this
|
|
80
|
-
normSign(): this
|
|
82
|
+
normSign(): this { if (this._magnitude === 0n)
|
|
83
|
+
this._sign = 0; return this; }
|
|
81
84
|
inspect(): string
|
|
82
85
|
toString(base: number | "hex" = 10, padding: number = 1): string
|
|
83
86
|
toNumber(): number
|
|
84
87
|
toJSON(): string
|
|
85
88
|
toArray(endian: "le" | "be" = "be", length?: number): number[]
|
|
86
|
-
bitLength(): number
|
|
89
|
+
bitLength(): number { if (this._magnitude === 0n)
|
|
90
|
+
return 0; return this._magnitude.toString(2).length; }
|
|
87
91
|
static toBitArray(num: BigNumber): Array<0 | 1>
|
|
88
92
|
toBitArray(): Array<0 | 1>
|
|
89
93
|
zeroBits(): number
|
|
90
|
-
byteLength(): number
|
|
91
|
-
|
|
94
|
+
byteLength(): number { if (this._magnitude === 0n)
|
|
95
|
+
return 0; return Math.ceil(this.bitLength() / 8); }
|
|
96
|
+
toTwos(width: number): BigNumber { this.assert(width >= 0); const Bw = BigInt(width); let v = this._getSignedValue(); if (this._sign === 1 && this._magnitude !== 0n)
|
|
97
|
+
v = (1n << Bw) + v; const m = (1n << Bw) - 1n; v &= m; const r = new BigNumber(0n); r._initializeState(v, 0); return r; }
|
|
92
98
|
fromTwos(width: number): BigNumber
|
|
93
99
|
isNeg(): boolean
|
|
94
100
|
neg(): BigNumber
|
|
95
|
-
ineg():
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
ineg(): this { if (this._magnitude !== 0n)
|
|
102
|
+
this._sign = this._sign === 1 ? 0 : 1; return this; }
|
|
103
|
+
iuor(num: BigNumber): this
|
|
104
|
+
iuand(num: BigNumber): this
|
|
105
|
+
iuxor(num: BigNumber): this
|
|
106
|
+
ior(num: BigNumber): this
|
|
107
|
+
iand(num: BigNumber): this
|
|
108
|
+
ixor(num: BigNumber): this
|
|
98
109
|
or(num: BigNumber): BigNumber
|
|
99
110
|
uor(num: BigNumber): BigNumber
|
|
100
|
-
iuand(num: BigNumber): BigNumber
|
|
101
|
-
iand(num: BigNumber): BigNumber
|
|
102
111
|
and(num: BigNumber): BigNumber
|
|
103
112
|
uand(num: BigNumber): BigNumber
|
|
104
|
-
iuxor(num: BigNumber): this
|
|
105
|
-
ixor(num: BigNumber): this
|
|
106
113
|
xor(num: BigNumber): BigNumber
|
|
107
114
|
uxor(num: BigNumber): BigNumber
|
|
108
|
-
inotn(width: number):
|
|
115
|
+
inotn(width: number): this
|
|
109
116
|
notn(width: number): BigNumber
|
|
110
|
-
setn(bit: number, val: 0
|
|
117
|
+
setn(bit: number, val: any): this { this.assert(typeof bit === "number" && bit >= 0); const Bb = BigInt(bit); if (val === 1 || val === true)
|
|
118
|
+
this._magnitude |= (1n << Bb);
|
|
119
|
+
else
|
|
120
|
+
this._magnitude &= ~(1n << Bb); const wnb = Math.floor(bit / BigNumber.wordSize) + 1; this._nominalWordLength = Math.max(this._nominalWordLength, wnb); this._finishInitialization(); return this.strip(); }
|
|
111
121
|
iadd(num: BigNumber): this
|
|
112
122
|
add(num: BigNumber): BigNumber
|
|
113
|
-
isub(num: BigNumber):
|
|
123
|
+
isub(num: BigNumber): this
|
|
114
124
|
sub(num: BigNumber): BigNumber
|
|
115
|
-
comb10MulTo(self: BigNumber, num: BigNumber, out: BigNumber): BigNumber
|
|
116
|
-
mulTo(num: BigNumber, out: BigNumber): BigNumber
|
|
117
125
|
mul(num: BigNumber): BigNumber
|
|
118
|
-
imul(num: BigNumber):
|
|
119
|
-
imuln(num: number):
|
|
126
|
+
imul(num: BigNumber): this
|
|
127
|
+
imuln(num: number): this
|
|
120
128
|
muln(num: number): BigNumber
|
|
121
129
|
sqr(): BigNumber
|
|
122
|
-
isqr():
|
|
130
|
+
isqr(): this
|
|
123
131
|
pow(num: BigNumber): BigNumber
|
|
124
|
-
iushln(bits: number): this
|
|
132
|
+
iushln(bits: number): this { this.assert(typeof bits === "number" && bits >= 0); if (bits === 0)
|
|
133
|
+
return this; this._magnitude <<= BigInt(bits); this._finishInitialization(); return this.strip(); }
|
|
125
134
|
ishln(bits: number): this
|
|
126
|
-
iushrn(bits: number, hint?: number, extended?: BigNumber): this
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
iushrn(bits: number, hint?: number, extended?: BigNumber): this { this.assert(typeof bits === "number" && bits >= 0); if (bits === 0) {
|
|
136
|
+
if (extended != null)
|
|
137
|
+
extended._initializeState(0n, 0);
|
|
138
|
+
return this;
|
|
139
|
+
} if (extended != null) {
|
|
140
|
+
const m = (1n << BigInt(bits)) - 1n;
|
|
141
|
+
const sOut = this._magnitude & m;
|
|
142
|
+
extended._initializeState(sOut, 0);
|
|
143
|
+
} this._magnitude >>= BigInt(bits); this._finishInitialization(); return this.strip(); }
|
|
144
|
+
ishrn(bits: number, hint?: number, extended?: BigNumber): this
|
|
145
|
+
shln(bits: number): BigNumber
|
|
146
|
+
ushln(bits: number): BigNumber
|
|
147
|
+
shrn(bits: number): BigNumber
|
|
148
|
+
ushrn(bits: number): BigNumber
|
|
132
149
|
testn(bit: number): boolean
|
|
133
|
-
imaskn(bits): this
|
|
134
|
-
maskn(bits): BigNumber
|
|
135
|
-
iaddn(num: number):
|
|
136
|
-
|
|
150
|
+
imaskn(bits: number): this
|
|
151
|
+
maskn(bits: number): BigNumber
|
|
152
|
+
iaddn(num: number): this
|
|
153
|
+
_iaddn(num: number): this
|
|
154
|
+
isubn(num: number): this
|
|
137
155
|
addn(num: number): BigNumber
|
|
138
156
|
subn(num: number): BigNumber
|
|
139
157
|
iabs(): this
|
|
140
158
|
abs(): BigNumber
|
|
141
|
-
_ishlnsubmul(num: BigNumber, mul, shift: number): this
|
|
142
159
|
divmod(num: BigNumber, mode?: "div" | "mod", positive?: boolean): any
|
|
143
160
|
div(num: BigNumber): BigNumber
|
|
144
161
|
mod(num: BigNumber): BigNumber
|
|
145
162
|
umod(num: BigNumber): BigNumber
|
|
146
163
|
divRound(num: BigNumber): BigNumber
|
|
147
|
-
modrn(
|
|
148
|
-
idivn(num: number):
|
|
164
|
+
modrn(numArg: number): number
|
|
165
|
+
idivn(num: number): this
|
|
149
166
|
divn(num: number): BigNumber
|
|
150
167
|
egcd(p: BigNumber): {
|
|
151
168
|
a: BigNumber;
|
|
152
169
|
b: BigNumber;
|
|
153
170
|
gcd: BigNumber;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
171
|
+
} { this.assert(p._sign === 0, "p must not be negative"); this.assert(!p.isZero(), "p must not be zero"); let uV = this._getSignedValue(); let vV = p._magnitude; let a = 1n; let pa = 0n; let b = 0n; let pb = 1n; while (vV !== 0n) {
|
|
172
|
+
const q = uV / vV;
|
|
173
|
+
let t = vV;
|
|
174
|
+
vV = uV % vV;
|
|
175
|
+
uV = t;
|
|
176
|
+
t = pa;
|
|
177
|
+
pa = a - q * pa;
|
|
178
|
+
a = t;
|
|
179
|
+
t = pb;
|
|
180
|
+
pb = b - q * pb;
|
|
181
|
+
b = t;
|
|
182
|
+
} const ra = new BigNumber(0n); ra._setValueFromSigned(a); const rb = new BigNumber(0n); rb._setValueFromSigned(b); const rg = new BigNumber(0n); rg._initializeState(uV < 0n ? -uV : uV, 0); return { a: ra, b: rb, gcd: rg }; }
|
|
183
|
+
gcd(num: BigNumber): BigNumber { let u = this._magnitude; let v = num._magnitude; if (u === 0n) {
|
|
184
|
+
const r = new BigNumber(0n);
|
|
185
|
+
r._setValueFromSigned(v);
|
|
186
|
+
return r.iabs();
|
|
187
|
+
} if (v === 0n) {
|
|
188
|
+
const r = new BigNumber(0n);
|
|
189
|
+
r._setValueFromSigned(u);
|
|
190
|
+
return r.iabs();
|
|
191
|
+
} while (v !== 0n) {
|
|
192
|
+
const t = u % v;
|
|
193
|
+
u = v;
|
|
194
|
+
v = t;
|
|
195
|
+
} const res = new BigNumber(0n); res._initializeState(u, 0); return res; }
|
|
157
196
|
invm(num: BigNumber): BigNumber
|
|
158
197
|
isEven(): boolean
|
|
159
198
|
isOdd(): boolean
|
|
160
199
|
andln(num: number): number
|
|
161
200
|
bincn(bit: number): this
|
|
162
201
|
isZero(): boolean
|
|
163
|
-
cmpn(num: number): 1 | 0 | -1
|
|
164
|
-
|
|
165
|
-
|
|
202
|
+
cmpn(num: number): 1 | 0 | -1 { this.assert(Math.abs(num) <= BigNumber.MAX_IMULN_ARG, "Number is too big"); const tV = this._getSignedValue(); const nV = BigInt(num); if (tV < nV)
|
|
203
|
+
return -1; if (tV > nV)
|
|
204
|
+
return 1; return 0; }
|
|
205
|
+
cmp(num: BigNumber): 1 | 0 | -1 { const tV = this._getSignedValue(); const nV = num._getSignedValue(); if (tV < nV)
|
|
206
|
+
return -1; if (tV > nV)
|
|
207
|
+
return 1; return 0; }
|
|
208
|
+
ucmp(num: BigNumber): 1 | 0 | -1 { if (this._magnitude < num._magnitude)
|
|
209
|
+
return -1; if (this._magnitude > num._magnitude)
|
|
210
|
+
return 1; return 0; }
|
|
166
211
|
gtn(num: number): boolean
|
|
167
212
|
gt(num: BigNumber): boolean
|
|
168
213
|
gten(num: number): boolean
|
|
@@ -189,17 +234,19 @@ export default class BigNumber {
|
|
|
189
234
|
redInvm(): BigNumber
|
|
190
235
|
redNeg(): BigNumber
|
|
191
236
|
redPow(num: BigNumber): BigNumber
|
|
192
|
-
static fromHex(hex: string, endian?: "little" | "big"): BigNumber
|
|
193
|
-
toHex(
|
|
237
|
+
static fromHex(hex: string, endian?: "le" | "be" | "little" | "big"): BigNumber
|
|
238
|
+
toHex(byteLength: number = 0): string
|
|
194
239
|
static fromJSON(str: string): BigNumber
|
|
195
240
|
static fromNumber(n: number): BigNumber
|
|
196
241
|
static fromString(str: string, base?: number | "hex"): BigNumber
|
|
197
|
-
static fromSm(
|
|
242
|
+
static fromSm(bytes: number[], endian: "big" | "little" = "big"): BigNumber
|
|
198
243
|
toSm(endian: "big" | "little" = "big"): number[]
|
|
199
244
|
static fromBits(bits: number, strict: boolean = false): BigNumber
|
|
200
245
|
toBits(): number
|
|
201
|
-
static fromScriptNum(num: number[], requireMinimal
|
|
246
|
+
static fromScriptNum(num: number[], requireMinimal: boolean = false, maxNumSize?: number): BigNumber
|
|
202
247
|
toScriptNum(): number[]
|
|
248
|
+
_invmp(p: BigNumber): BigNumber
|
|
249
|
+
mulTo(num: BigNumber, out: BigNumber): BigNumber
|
|
203
250
|
}
|
|
204
251
|
```
|
|
205
252
|
|
|
@@ -208,7 +255,7 @@ See also: [ReductionContext](./primitives.md#class-reductioncontext), [toArray](
|
|
|
208
255
|
#### Constructor
|
|
209
256
|
|
|
210
257
|
```ts
|
|
211
|
-
constructor(number: number | string | number[] = 0, base: number | "be" | "le" | "hex" = 10, endian: "be" | "le" = "be")
|
|
258
|
+
constructor(number: number | string | number[] | bigint | undefined = 0, base: number | "be" | "le" | "hex" = 10, endian: "be" | "le" = "be")
|
|
212
259
|
```
|
|
213
260
|
|
|
214
261
|
Argument Details
|
|
@@ -220,51 +267,12 @@ Argument Details
|
|
|
220
267
|
+ **endian**
|
|
221
268
|
+ The endianness provided. By default is 'big endian'.
|
|
222
269
|
|
|
223
|
-
Example
|
|
224
|
-
|
|
225
|
-
```ts
|
|
226
|
-
import BigNumber from './BigNumber';
|
|
227
|
-
const bn = new BigNumber('123456', 10, 'be');
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
#### Property length
|
|
231
|
-
|
|
232
|
-
Length of the words array.
|
|
233
|
-
|
|
234
|
-
```ts
|
|
235
|
-
length: number
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
Example
|
|
239
|
-
|
|
240
|
-
```ts
|
|
241
|
-
let num = new BigNumber(50000);
|
|
242
|
-
console.log(num.length); // output: 1
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
#### Property negative
|
|
246
|
-
|
|
247
|
-
Negative flag. Indicates whether the big number is a negative number.
|
|
248
|
-
- If 0, the number is positive.
|
|
249
|
-
- If 1, the number is negative.
|
|
250
|
-
|
|
251
|
-
```ts
|
|
252
|
-
negative: number
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
Example
|
|
256
|
-
|
|
257
|
-
```ts
|
|
258
|
-
let num = new BigNumber("-10");
|
|
259
|
-
console.log(num.negative); // output: 1
|
|
260
|
-
```
|
|
261
|
-
|
|
262
270
|
#### Property red
|
|
263
271
|
|
|
264
272
|
Reduction context of the big number.
|
|
265
273
|
|
|
266
274
|
```ts
|
|
267
|
-
red: ReductionContext | null
|
|
275
|
+
public red: ReductionContext | null
|
|
268
276
|
```
|
|
269
277
|
See also: [ReductionContext](./primitives.md#class-reductioncontext)
|
|
270
278
|
|
|
@@ -282,21 +290,6 @@ Example
|
|
|
282
290
|
console.log(BigNumber.wordSize); // output: 26
|
|
283
291
|
```
|
|
284
292
|
|
|
285
|
-
#### Property words
|
|
286
|
-
|
|
287
|
-
Array of numbers, where each number represents a part of the value of the big number.
|
|
288
|
-
|
|
289
|
-
```ts
|
|
290
|
-
words: number[]
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
Example
|
|
294
|
-
|
|
295
|
-
```ts
|
|
296
|
-
let num = new BigNumber(50000);
|
|
297
|
-
console.log(num.words); // output: [ 50000 ]
|
|
298
|
-
```
|
|
299
|
-
|
|
300
293
|
#### Method _invmp
|
|
301
294
|
|
|
302
295
|
Compute the multiplicative inverse of the current BigNumber in the modulus field specified by `p`.
|
|
@@ -316,2894 +309,372 @@ Argument Details
|
|
|
316
309
|
+ **p**
|
|
317
310
|
+ The `BigNumber` specifying the modulus field.
|
|
318
311
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
```ts
|
|
322
|
-
const bigNum = new BigNumber('45');
|
|
323
|
-
const p = new BigNumber('100');
|
|
324
|
-
const inverse = bigNum._invmp(p); // inverse here would be a BigNumber such that (inverse*bigNum) % p = '1'
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
#### Method _ishlnsubmul
|
|
312
|
+
#### Method bitLength
|
|
328
313
|
|
|
329
|
-
|
|
330
|
-
This method modifies the existing BigNumber instance.
|
|
314
|
+
Calculates the number of bits required to represent the BigNumber.
|
|
331
315
|
|
|
332
316
|
```ts
|
|
333
|
-
|
|
317
|
+
bitLength(): number { if (this._magnitude === 0n)
|
|
318
|
+
return 0; return this._magnitude.toString(2).length; }
|
|
334
319
|
```
|
|
335
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
336
320
|
|
|
337
321
|
Returns
|
|
338
322
|
|
|
339
|
-
|
|
323
|
+
The bit length of the BigNumber.
|
|
340
324
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
+ **num**
|
|
344
|
-
+ The BigNumber to be operated on.
|
|
345
|
-
+ **mul**
|
|
346
|
-
+ The multiplication factor.
|
|
347
|
-
+ **shift**
|
|
348
|
-
+ The number of places to shift left.
|
|
325
|
+
#### Method byteLength
|
|
349
326
|
|
|
350
|
-
|
|
327
|
+
Calculates the number of bytes required to represent the BigNumber.
|
|
351
328
|
|
|
352
329
|
```ts
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
console.log(number.toString()); // Outputs result after performing operations
|
|
330
|
+
byteLength(): number { if (this._magnitude === 0n)
|
|
331
|
+
return 0; return Math.ceil(this.bitLength() / 8); }
|
|
356
332
|
```
|
|
357
333
|
|
|
358
|
-
|
|
334
|
+
Returns
|
|
335
|
+
|
|
336
|
+
The byte length of the BigNumber.
|
|
337
|
+
|
|
338
|
+
#### Method fromBits
|
|
359
339
|
|
|
360
|
-
|
|
361
|
-
This operation does not affect the actual object but instead returns a new instance of BigNumber.
|
|
340
|
+
Creates a BigNumber from a number representing the "bits" value in a block header.
|
|
362
341
|
|
|
363
342
|
```ts
|
|
364
|
-
|
|
343
|
+
static fromBits(bits: number, strict: boolean = false): BigNumber
|
|
365
344
|
```
|
|
366
345
|
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
367
346
|
|
|
368
347
|
Returns
|
|
369
348
|
|
|
370
|
-
a
|
|
349
|
+
Returns a BigNumber equivalent to the "bits" value in a block header.
|
|
350
|
+
|
|
351
|
+
Argument Details
|
|
371
352
|
|
|
372
|
-
|
|
353
|
+
+ **bits**
|
|
354
|
+
+ The number representing the bits value in a block header.
|
|
355
|
+
+ **strict**
|
|
356
|
+
+ If true, an error is thrown if the number has negative bit set.
|
|
373
357
|
|
|
374
|
-
|
|
375
|
-
let negativeNumber = new BigNumber(-10);
|
|
376
|
-
let absolute = negativeNumber.abs();
|
|
377
|
-
console.log(absolute.toString()); // Outputs: "10"
|
|
378
|
-
```
|
|
358
|
+
Throws
|
|
379
359
|
|
|
380
|
-
|
|
360
|
+
Will throw an error if `strict` is `true` and the number has negative bit set.
|
|
381
361
|
|
|
382
|
-
|
|
362
|
+
#### Method fromHex
|
|
363
|
+
|
|
364
|
+
Creates a BigNumber from a hexadecimal string.
|
|
383
365
|
|
|
384
366
|
```ts
|
|
385
|
-
|
|
367
|
+
static fromHex(hex: string, endian?: "le" | "be" | "little" | "big"): BigNumber
|
|
386
368
|
```
|
|
387
369
|
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
388
370
|
|
|
389
371
|
Returns
|
|
390
372
|
|
|
391
|
-
Returns a
|
|
373
|
+
Returns a BigNumber created from the hexadecimal input string.
|
|
392
374
|
|
|
393
375
|
Argument Details
|
|
394
376
|
|
|
395
|
-
+ **
|
|
396
|
-
+ The
|
|
377
|
+
+ **hex**
|
|
378
|
+
+ The hexadecimal string to create a BigNumber from.
|
|
379
|
+
+ **endian**
|
|
380
|
+
+ Optional endianness for parsing the hex string.
|
|
397
381
|
|
|
398
382
|
Example
|
|
399
383
|
|
|
400
384
|
```ts
|
|
401
|
-
const
|
|
402
|
-
const
|
|
403
|
-
console.log(addResult.toString());
|
|
385
|
+
const exampleHex = 'a1b2c3';
|
|
386
|
+
const bigNumber = BigNumber.fromHex(exampleHex);
|
|
404
387
|
```
|
|
405
388
|
|
|
406
|
-
#### Method
|
|
389
|
+
#### Method fromJSON
|
|
407
390
|
|
|
408
|
-
|
|
391
|
+
Creates a BigNumber from a JSON-serialized string.
|
|
409
392
|
|
|
410
393
|
```ts
|
|
411
|
-
|
|
394
|
+
static fromJSON(str: string): BigNumber
|
|
412
395
|
```
|
|
413
396
|
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
414
397
|
|
|
415
398
|
Returns
|
|
416
399
|
|
|
417
|
-
Returns a
|
|
400
|
+
Returns a BigNumber created from the JSON input string.
|
|
418
401
|
|
|
419
402
|
Argument Details
|
|
420
403
|
|
|
421
|
-
+ **
|
|
422
|
-
+ The
|
|
423
|
-
|
|
424
|
-
Example
|
|
425
|
-
|
|
426
|
-
```ts
|
|
427
|
-
const myNumber = new BigNumber(50);
|
|
428
|
-
const newNumber = myNumber.addn(2); // newNumber becomes 52, myNumber doesn't change.
|
|
429
|
-
```
|
|
404
|
+
+ **str**
|
|
405
|
+
+ The JSON-serialized string to create a BigNumber from.
|
|
430
406
|
|
|
431
|
-
#### Method
|
|
407
|
+
#### Method fromNumber
|
|
432
408
|
|
|
433
|
-
|
|
434
|
-
set in the result only if the corresponding bit is set in both operands.
|
|
409
|
+
Creates a BigNumber from a number.
|
|
435
410
|
|
|
436
411
|
```ts
|
|
437
|
-
|
|
412
|
+
static fromNumber(n: number): BigNumber
|
|
438
413
|
```
|
|
439
414
|
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
440
415
|
|
|
441
416
|
Returns
|
|
442
417
|
|
|
443
|
-
Returns
|
|
418
|
+
Returns a BigNumber equivalent to the input number.
|
|
444
419
|
|
|
445
420
|
Argument Details
|
|
446
421
|
|
|
447
|
-
+ **
|
|
448
|
-
+ The
|
|
449
|
-
|
|
450
|
-
Example
|
|
451
|
-
|
|
452
|
-
```ts
|
|
453
|
-
const num1 = new BigNumber('10');
|
|
454
|
-
const num2 = new BigNumber('20');
|
|
455
|
-
console.log(num1.and(num2).toString());
|
|
456
|
-
```
|
|
422
|
+
+ **n**
|
|
423
|
+
+ The number to create a BigNumber from.
|
|
457
424
|
|
|
458
|
-
#### Method
|
|
425
|
+
#### Method fromScriptNum
|
|
459
426
|
|
|
460
|
-
|
|
461
|
-
this BigNumber and the provided number.
|
|
462
|
-
This method is mostly used to mask-off less significant bits.
|
|
427
|
+
Creates a BigNumber from the format used in Bitcoin scripts.
|
|
463
428
|
|
|
464
429
|
```ts
|
|
465
|
-
|
|
430
|
+
static fromScriptNum(num: number[], requireMinimal: boolean = false, maxNumSize?: number): BigNumber
|
|
466
431
|
```
|
|
432
|
+
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
467
433
|
|
|
468
434
|
Returns
|
|
469
435
|
|
|
470
|
-
|
|
436
|
+
Returns a BigNumber equivalent to the number used in a Bitcoin script.
|
|
471
437
|
|
|
472
438
|
Argument Details
|
|
473
439
|
|
|
474
440
|
+ **num**
|
|
475
|
-
+ The number
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
let a = new BigNumber(60);
|
|
481
|
-
let result = a.andln(13); // 12
|
|
482
|
-
```
|
|
441
|
+
+ The number in the format used in Bitcoin scripts.
|
|
442
|
+
+ **requireMinimal**
|
|
443
|
+
+ If true, non-minimally encoded values will throw an error.
|
|
444
|
+
+ **maxNumSize**
|
|
445
|
+
+ The maximum allowed size for the number.
|
|
483
446
|
|
|
484
|
-
#### Method
|
|
447
|
+
#### Method fromSm
|
|
485
448
|
|
|
486
|
-
|
|
449
|
+
Creates a BigNumber from a signed magnitude number.
|
|
487
450
|
|
|
488
451
|
```ts
|
|
489
|
-
|
|
452
|
+
static fromSm(bytes: number[], endian: "big" | "little" = "big"): BigNumber
|
|
490
453
|
```
|
|
454
|
+
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
491
455
|
|
|
492
456
|
Returns
|
|
493
457
|
|
|
494
|
-
|
|
458
|
+
Returns a BigNumber equivalent to the signed magnitude number interpreted with specified endianess.
|
|
495
459
|
|
|
496
460
|
Argument Details
|
|
497
461
|
|
|
498
|
-
+ **
|
|
499
|
-
+ The
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
```ts
|
|
504
|
-
let a = new BigNumber(5);
|
|
505
|
-
a.bincn(2); // a = 7
|
|
506
|
-
```
|
|
462
|
+
+ **bytes**
|
|
463
|
+
+ The signed magnitude number to convert to a BigNumber.
|
|
464
|
+
+ **endian**
|
|
465
|
+
+ Defines endianess. If not provided, big endian is assumed.
|
|
507
466
|
|
|
508
|
-
#### Method
|
|
467
|
+
#### Method fromString
|
|
509
468
|
|
|
510
|
-
|
|
469
|
+
Creates a BigNumber from a string, considering an optional base.
|
|
511
470
|
|
|
512
471
|
```ts
|
|
513
|
-
|
|
472
|
+
static fromString(str: string, base?: number | "hex"): BigNumber
|
|
514
473
|
```
|
|
474
|
+
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
515
475
|
|
|
516
476
|
Returns
|
|
517
477
|
|
|
518
|
-
|
|
478
|
+
Returns a BigNumber equivalent to the string after conversion from the specified base.
|
|
519
479
|
|
|
520
|
-
|
|
480
|
+
Argument Details
|
|
521
481
|
|
|
522
|
-
|
|
482
|
+
+ **str**
|
|
483
|
+
+ The string to create a BigNumber from.
|
|
484
|
+
+ **base**
|
|
485
|
+
+ The base used for conversion. If not provided, base 10 is assumed.
|
|
486
|
+
|
|
487
|
+
#### Method isBN
|
|
488
|
+
|
|
489
|
+
Checks whether a value is an instance of BigNumber. Regular JS numbers fail this check.
|
|
523
490
|
|
|
524
491
|
```ts
|
|
525
|
-
|
|
492
|
+
static isBN(num: any): boolean
|
|
526
493
|
```
|
|
527
494
|
|
|
528
495
|
Returns
|
|
529
496
|
|
|
530
|
-
Returns
|
|
497
|
+
- Returns a boolean value determining whether or not the checked num parameter is a BigNumber.
|
|
531
498
|
|
|
532
|
-
|
|
499
|
+
Argument Details
|
|
533
500
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
const bn = new BigNumber('1234');
|
|
537
|
-
const byteLen = bn.byteLength();
|
|
538
|
-
```
|
|
501
|
+
+ **num**
|
|
502
|
+
+ The value to be checked.
|
|
539
503
|
|
|
540
|
-
#### Method
|
|
504
|
+
#### Method max
|
|
541
505
|
|
|
542
|
-
|
|
506
|
+
Returns the bigger value between two BigNumbers
|
|
543
507
|
|
|
544
508
|
```ts
|
|
545
|
-
|
|
509
|
+
static max(left: BigNumber, right: BigNumber): BigNumber
|
|
546
510
|
```
|
|
547
511
|
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
548
512
|
|
|
549
513
|
Returns
|
|
550
514
|
|
|
551
|
-
|
|
515
|
+
- Returns the bigger BigNumber between left and right.
|
|
552
516
|
|
|
553
|
-
|
|
517
|
+
Argument Details
|
|
554
518
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
519
|
+
+ **left**
|
|
520
|
+
+ The first BigNumber to be compared.
|
|
521
|
+
+ **right**
|
|
522
|
+
+ The second BigNumber to be compared.
|
|
559
523
|
|
|
560
|
-
#### Method
|
|
524
|
+
#### Method min
|
|
561
525
|
|
|
562
|
-
|
|
526
|
+
Returns the smaller value between two BigNumbers
|
|
563
527
|
|
|
564
528
|
```ts
|
|
565
|
-
|
|
529
|
+
static min(left: BigNumber, right: BigNumber): BigNumber
|
|
566
530
|
```
|
|
567
531
|
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
568
532
|
|
|
569
533
|
Returns
|
|
570
534
|
|
|
571
|
-
Returns
|
|
572
|
-
1 if this big number is greater,
|
|
573
|
-
-1 if it's less,
|
|
574
|
-
0 if they are equal.
|
|
535
|
+
- Returns the smaller value between left and right.
|
|
575
536
|
|
|
576
537
|
Argument Details
|
|
577
538
|
|
|
578
|
-
+ **
|
|
579
|
-
+ The
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
```ts
|
|
584
|
-
import BigNumber from './BigNumber';
|
|
585
|
-
const bn1 = new BigNumber('10');
|
|
586
|
-
const bn2 = new BigNumber('6');
|
|
587
|
-
const comparisonResult = bn1.cmp(bn2); // 1 - because 10 is greater than 6
|
|
588
|
-
```
|
|
539
|
+
+ **left**
|
|
540
|
+
+ The first BigNumber to be compared.
|
|
541
|
+
+ **right**
|
|
542
|
+
+ The second BigNumber to be compared.
|
|
589
543
|
|
|
590
|
-
#### Method
|
|
544
|
+
#### Method mulTo
|
|
591
545
|
|
|
592
|
-
|
|
593
|
-
It
|
|
546
|
+
Performs multiplication between the BigNumber instance and a given BigNumber.
|
|
547
|
+
It chooses the multiplication method based on the lengths of the numbers to optimize execution time.
|
|
594
548
|
|
|
595
549
|
```ts
|
|
596
|
-
|
|
550
|
+
mulTo(num: BigNumber, out: BigNumber): BigNumber
|
|
597
551
|
```
|
|
552
|
+
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
598
553
|
|
|
599
554
|
Returns
|
|
600
555
|
|
|
601
|
-
|
|
556
|
+
The BigNumber resulting from the multiplication operation.
|
|
602
557
|
|
|
603
558
|
Argument Details
|
|
604
559
|
|
|
605
560
|
+ **num**
|
|
606
|
-
+ The
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
```ts
|
|
611
|
-
let a = new BigNumber(15);
|
|
612
|
-
let result = a.cmpn(10); // 1
|
|
613
|
-
```
|
|
561
|
+
+ The BigNumber multiply with.
|
|
562
|
+
+ **out**
|
|
563
|
+
+ The BigNumber where to store the result.
|
|
614
564
|
|
|
615
|
-
#### Method
|
|
565
|
+
#### Method toArray
|
|
616
566
|
|
|
617
|
-
|
|
567
|
+
Converts the BigNumber instance to an array of bytes.
|
|
618
568
|
|
|
619
569
|
```ts
|
|
620
|
-
|
|
570
|
+
toArray(endian: "le" | "be" = "be", length?: number): number[]
|
|
621
571
|
```
|
|
622
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
623
572
|
|
|
624
|
-
|
|
573
|
+
Returns
|
|
625
574
|
|
|
626
|
-
|
|
627
|
-
+ The BigNumber instance that will be updated to become a copy.
|
|
575
|
+
Array of bytes representing the BigNumber.
|
|
628
576
|
|
|
629
|
-
|
|
577
|
+
Argument Details
|
|
630
578
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
// bn2 is now a BigNumber representing 123456
|
|
636
|
-
```
|
|
579
|
+
+ **endian**
|
|
580
|
+
+ Endianness of the output array, defaults to 'be'.
|
|
581
|
+
+ **length**
|
|
582
|
+
+ Optional length of the output array.
|
|
637
583
|
|
|
638
|
-
#### Method
|
|
584
|
+
#### Method toBitArray
|
|
639
585
|
|
|
640
|
-
|
|
586
|
+
Converts a BigNumber to an array of bits.
|
|
641
587
|
|
|
642
588
|
```ts
|
|
643
|
-
|
|
589
|
+
static toBitArray(num: BigNumber): Array<0 | 1>
|
|
644
590
|
```
|
|
645
591
|
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
646
592
|
|
|
647
593
|
Returns
|
|
648
594
|
|
|
649
|
-
|
|
595
|
+
An array of bits.
|
|
650
596
|
|
|
651
597
|
Argument Details
|
|
652
598
|
|
|
653
599
|
+ **num**
|
|
654
|
-
+ The BigNumber to
|
|
600
|
+
+ The BigNumber to convert.
|
|
655
601
|
|
|
656
|
-
|
|
602
|
+
#### Method toBits
|
|
603
|
+
|
|
604
|
+
Converts this BigNumber to a number representing the "bits" value in a block header.
|
|
657
605
|
|
|
658
606
|
```ts
|
|
659
|
-
|
|
660
|
-
let result = number.div(new BigNumber(2));
|
|
661
|
-
console.log(result.toString()); // Outputs: "5"
|
|
607
|
+
toBits(): number
|
|
662
608
|
```
|
|
663
609
|
|
|
664
|
-
|
|
610
|
+
Returns
|
|
611
|
+
|
|
612
|
+
Returns a number equivalent to the "bits" value in a block header.
|
|
613
|
+
|
|
614
|
+
#### Method toHex
|
|
665
615
|
|
|
666
|
-
|
|
616
|
+
Converts this BigNumber to a hexadecimal string.
|
|
667
617
|
|
|
668
618
|
```ts
|
|
669
|
-
|
|
619
|
+
toHex(byteLength: number = 0): string
|
|
670
620
|
```
|
|
671
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
672
621
|
|
|
673
622
|
Returns
|
|
674
623
|
|
|
675
|
-
|
|
624
|
+
Returns a string representing the hexadecimal value of this BigNumber.
|
|
676
625
|
|
|
677
626
|
Argument Details
|
|
678
627
|
|
|
679
|
-
+ **
|
|
680
|
-
+ The
|
|
628
|
+
+ **length**
|
|
629
|
+
+ The minimum length of the hex string
|
|
681
630
|
|
|
682
631
|
Example
|
|
683
632
|
|
|
684
633
|
```ts
|
|
685
|
-
const
|
|
686
|
-
const
|
|
687
|
-
const quotient = bigNum1.divRound(bigNum2); // quotient here would be '2'
|
|
634
|
+
const bigNumber = new BigNumber(255)
|
|
635
|
+
const hex = bigNumber.toHex()
|
|
688
636
|
```
|
|
689
637
|
|
|
690
|
-
#### Method
|
|
638
|
+
#### Method toJSON
|
|
691
639
|
|
|
692
|
-
|
|
693
|
-
If the mode parameter is not provided, both division and modulus results are returned.
|
|
640
|
+
Converts the BigNumber instance to a JSON-formatted string.
|
|
694
641
|
|
|
695
642
|
```ts
|
|
696
|
-
|
|
643
|
+
toJSON(): string
|
|
697
644
|
```
|
|
698
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
699
645
|
|
|
700
646
|
Returns
|
|
701
647
|
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
Argument Details
|
|
648
|
+
The JSON string representation of the BigNumber instance.
|
|
705
649
|
|
|
706
|
-
|
|
707
|
-
+ The BigNumber to divide by.
|
|
708
|
-
+ **mode**
|
|
709
|
-
+ Specifies operation as 'mod' for modulus, 'div' for division, or both if not specified.
|
|
710
|
-
+ **positive**
|
|
711
|
-
+ Specifies if unsigned modulus is requested.
|
|
650
|
+
#### Method toNumber
|
|
712
651
|
|
|
713
|
-
|
|
652
|
+
Converts the BigNumber instance to a JavaScript number.
|
|
653
|
+
Please note that JavaScript numbers are only precise up to 53 bits.
|
|
714
654
|
|
|
715
655
|
```ts
|
|
716
|
-
|
|
717
|
-
let result = number.divmod(new BigNumber(3));
|
|
718
|
-
console.log(result.div.toString()); // Outputs: "3"
|
|
719
|
-
console.log(result.mod.toString()); // Outputs: "1"
|
|
656
|
+
toNumber(): number
|
|
720
657
|
```
|
|
721
658
|
|
|
722
|
-
|
|
659
|
+
Returns
|
|
660
|
+
|
|
661
|
+
The JavaScript number representation of the BigNumber instance.
|
|
662
|
+
|
|
663
|
+
Throws
|
|
664
|
+
|
|
665
|
+
If the BigNumber instance cannot be safely stored in a JavaScript number
|
|
666
|
+
|
|
667
|
+
#### Method toScriptNum
|
|
723
668
|
|
|
724
|
-
|
|
669
|
+
Converts this BigNumber to a number in the format used in Bitcoin scripts.
|
|
725
670
|
|
|
726
671
|
```ts
|
|
727
|
-
|
|
672
|
+
toScriptNum(): number[]
|
|
728
673
|
```
|
|
729
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
730
674
|
|
|
731
675
|
Returns
|
|
732
676
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
Argument Details
|
|
736
|
-
|
|
737
|
-
+ **num**
|
|
738
|
-
+ The divisor primitive number.
|
|
739
|
-
|
|
740
|
-
Example
|
|
741
|
-
|
|
742
|
-
```ts
|
|
743
|
-
const bigNum = new BigNumber('100');
|
|
744
|
-
const num = 45;
|
|
745
|
-
const quotient = bigNum.divn(num); // quotient here would be '2'
|
|
746
|
-
```
|
|
747
|
-
|
|
748
|
-
#### Method egcd
|
|
749
|
-
|
|
750
|
-
Computes the Extended Euclidean Algorithm for this BigNumber and provided BigNumber `p`.
|
|
751
|
-
The Extended Euclidean Algorithm is a method to find the GCD (Greatest Common Divisor) and the multiplicative inverse in a modulus field.
|
|
752
|
-
|
|
753
|
-
```ts
|
|
754
|
-
egcd(p: BigNumber): {
|
|
755
|
-
a: BigNumber;
|
|
756
|
-
b: BigNumber;
|
|
757
|
-
gcd: BigNumber;
|
|
758
|
-
}
|
|
759
|
-
```
|
|
760
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
761
|
-
|
|
762
|
-
Returns
|
|
763
|
-
|
|
764
|
-
An object `{a: BigNumber, b: BigNumber, gcd: BigNumber}` where `gcd` is the GCD of the numbers, `a` is the coefficient of `this`, and `b` is the coefficient of `p` in Bézout's identity.
|
|
765
|
-
|
|
766
|
-
Argument Details
|
|
767
|
-
|
|
768
|
-
+ **p**
|
|
769
|
-
+ The `BigNumber` with which the Extended Euclidean Algorithm will be computed.
|
|
770
|
-
|
|
771
|
-
Example
|
|
772
|
-
|
|
773
|
-
```ts
|
|
774
|
-
const bigNum1 = new BigNumber('100');
|
|
775
|
-
const bigNum2 = new BigNumber('45');
|
|
776
|
-
const result = bigNum1.egcd(bigNum2);
|
|
777
|
-
```
|
|
778
|
-
|
|
779
|
-
#### Method eq
|
|
780
|
-
|
|
781
|
-
Compares the current BigNumber with the given number and returns whether they're equal.
|
|
782
|
-
|
|
783
|
-
```ts
|
|
784
|
-
eq(num: BigNumber): boolean
|
|
785
|
-
```
|
|
786
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
787
|
-
|
|
788
|
-
Returns
|
|
789
|
-
|
|
790
|
-
Returns true if the current BigNumber is equal to the provided number, otherwise false.
|
|
791
|
-
|
|
792
|
-
Argument Details
|
|
793
|
-
|
|
794
|
-
+ **num**
|
|
795
|
-
+ The number to compare equality with.
|
|
796
|
-
|
|
797
|
-
Example
|
|
798
|
-
|
|
799
|
-
```ts
|
|
800
|
-
let bigNum = new BigNumber(10);
|
|
801
|
-
bigNum.eq(new BigNumber(10)); // true
|
|
802
|
-
```
|
|
803
|
-
|
|
804
|
-
#### Method eqn
|
|
805
|
-
|
|
806
|
-
Checks if this BigNumber instance is equal to a number.
|
|
807
|
-
|
|
808
|
-
```ts
|
|
809
|
-
eqn(num: number): boolean
|
|
810
|
-
```
|
|
811
|
-
|
|
812
|
-
Returns
|
|
813
|
-
|
|
814
|
-
Returns true if this BigNumber is equal to the number, false otherwise.
|
|
815
|
-
|
|
816
|
-
Argument Details
|
|
817
|
-
|
|
818
|
-
+ **num**
|
|
819
|
-
+ The number to compare with.
|
|
820
|
-
|
|
821
|
-
Example
|
|
822
|
-
|
|
823
|
-
```ts
|
|
824
|
-
let bigNumber = new BigNumber('1234');
|
|
825
|
-
let isEqual = bigNumber.eqn(1234); // Returns true
|
|
826
|
-
```
|
|
827
|
-
|
|
828
|
-
#### Method expand
|
|
829
|
-
|
|
830
|
-
Increases the BigNumber length up to a certain size and initializes new elements with 0.
|
|
831
|
-
|
|
832
|
-
```ts
|
|
833
|
-
expand(size: number): this
|
|
834
|
-
```
|
|
835
|
-
|
|
836
|
-
Returns
|
|
837
|
-
|
|
838
|
-
The BigNumber instance after expansion.
|
|
839
|
-
|
|
840
|
-
Argument Details
|
|
841
|
-
|
|
842
|
-
+ **size**
|
|
843
|
-
+ The desired size to grow the BigNumber length.
|
|
844
|
-
|
|
845
|
-
Example
|
|
846
|
-
|
|
847
|
-
```ts
|
|
848
|
-
const bn = new BigNumber('123456', 10, 'be');
|
|
849
|
-
bn.expand(10);
|
|
850
|
-
```
|
|
851
|
-
|
|
852
|
-
#### Method forceRed
|
|
853
|
-
|
|
854
|
-
Forces the current BigNumber into a reduction context, irrespective of the BigNumber's current state.
|
|
855
|
-
|
|
856
|
-
```ts
|
|
857
|
-
forceRed(ctx: ReductionContext): this
|
|
858
|
-
```
|
|
859
|
-
See also: [ReductionContext](./primitives.md#class-reductioncontext)
|
|
860
|
-
|
|
861
|
-
Returns
|
|
862
|
-
|
|
863
|
-
Returns the BigNumber in the given ReductionContext.
|
|
864
|
-
|
|
865
|
-
Argument Details
|
|
866
|
-
|
|
867
|
-
+ **ctx**
|
|
868
|
-
+ The ReductionContext to forcefully convert the BigNumber to.
|
|
869
|
-
|
|
870
|
-
Example
|
|
871
|
-
|
|
872
|
-
```ts
|
|
873
|
-
let bigNum = new BigNumber(10);
|
|
874
|
-
let redCtx = new ReductionContext();
|
|
875
|
-
bigNum.forceRed(redCtx);
|
|
876
|
-
```
|
|
877
|
-
|
|
878
|
-
#### Method fromBits
|
|
879
|
-
|
|
880
|
-
Creates a BigNumber from a number representing the "bits" value in a block header.
|
|
881
|
-
|
|
882
|
-
```ts
|
|
883
|
-
static fromBits(bits: number, strict: boolean = false): BigNumber
|
|
884
|
-
```
|
|
885
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
886
|
-
|
|
887
|
-
Returns
|
|
888
|
-
|
|
889
|
-
Returns a BigNumber equivalent to the "bits" value in a block header.
|
|
890
|
-
|
|
891
|
-
Argument Details
|
|
892
|
-
|
|
893
|
-
+ **bits**
|
|
894
|
-
+ The number representing the bits value in a block header.
|
|
895
|
-
+ **strict**
|
|
896
|
-
+ If true, an error is thrown if the number has negative bit set.
|
|
897
|
-
|
|
898
|
-
Throws
|
|
899
|
-
|
|
900
|
-
Will throw an error if `strict` is `true` and the number has negative bit set.
|
|
901
|
-
|
|
902
|
-
Example
|
|
903
|
-
|
|
904
|
-
```ts
|
|
905
|
-
const bits = 0x1d00ffff;
|
|
906
|
-
const bigNumber = BigNumber.fromBits(bits);
|
|
907
|
-
```
|
|
908
|
-
|
|
909
|
-
#### Method fromHex
|
|
910
|
-
|
|
911
|
-
Creates a BigNumber from a hexadecimal string.
|
|
912
|
-
|
|
913
|
-
```ts
|
|
914
|
-
static fromHex(hex: string, endian?: "little" | "big"): BigNumber
|
|
915
|
-
```
|
|
916
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
917
|
-
|
|
918
|
-
Returns
|
|
919
|
-
|
|
920
|
-
Returns a BigNumber created from the hexadecimal input string.
|
|
921
|
-
|
|
922
|
-
Argument Details
|
|
923
|
-
|
|
924
|
-
+ **hex**
|
|
925
|
-
+ The hexadecimal string to create a BigNumber from.
|
|
926
|
-
|
|
927
|
-
Example
|
|
928
|
-
|
|
929
|
-
```ts
|
|
930
|
-
const exampleHex = 'a1b2c3';
|
|
931
|
-
const bigNumber = BigNumber.fromHex(exampleHex);
|
|
932
|
-
```
|
|
933
|
-
|
|
934
|
-
#### Method fromJSON
|
|
935
|
-
|
|
936
|
-
Creates a BigNumber from a JSON-serialized string.
|
|
937
|
-
|
|
938
|
-
```ts
|
|
939
|
-
static fromJSON(str: string): BigNumber
|
|
940
|
-
```
|
|
941
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
942
|
-
|
|
943
|
-
Returns
|
|
944
|
-
|
|
945
|
-
Returns a BigNumber created from the JSON input string.
|
|
946
|
-
|
|
947
|
-
Argument Details
|
|
948
|
-
|
|
949
|
-
+ **str**
|
|
950
|
-
+ The JSON-serialized string to create a BigNumber from.
|
|
951
|
-
|
|
952
|
-
Example
|
|
953
|
-
|
|
954
|
-
```ts
|
|
955
|
-
const serialized = '{"type":"BigNumber","hex":"a1b2c3"}';
|
|
956
|
-
const bigNumber = BigNumber.fromJSON(serialized);
|
|
957
|
-
```
|
|
958
|
-
|
|
959
|
-
#### Method fromNumber
|
|
960
|
-
|
|
961
|
-
Creates a BigNumber from a number.
|
|
962
|
-
|
|
963
|
-
```ts
|
|
964
|
-
static fromNumber(n: number): BigNumber
|
|
965
|
-
```
|
|
966
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
967
|
-
|
|
968
|
-
Returns
|
|
969
|
-
|
|
970
|
-
Returns a BigNumber equivalent to the input number.
|
|
971
|
-
|
|
972
|
-
Argument Details
|
|
973
|
-
|
|
974
|
-
+ **n**
|
|
975
|
-
+ The number to create a BigNumber from.
|
|
976
|
-
|
|
977
|
-
Example
|
|
978
|
-
|
|
979
|
-
```ts
|
|
980
|
-
const number = 1234;
|
|
981
|
-
const bigNumber = BigNumber.fromNumber(number);
|
|
982
|
-
```
|
|
983
|
-
|
|
984
|
-
#### Method fromRed
|
|
985
|
-
|
|
986
|
-
Converts a BigNumber from a reduction context, making sure the number is indeed in a reduction context.
|
|
987
|
-
Throws an error in case the number is not in a reduction context.
|
|
988
|
-
|
|
989
|
-
```ts
|
|
990
|
-
fromRed(): BigNumber
|
|
991
|
-
```
|
|
992
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
993
|
-
|
|
994
|
-
Returns
|
|
995
|
-
|
|
996
|
-
Returns the BigNumber out of the ReductionContext.
|
|
997
|
-
|
|
998
|
-
Example
|
|
999
|
-
|
|
1000
|
-
```ts
|
|
1001
|
-
let bigNum = new BigNumber(10);
|
|
1002
|
-
let redCtx = new ReductionContext();
|
|
1003
|
-
bigNum.toRed(redCtx);
|
|
1004
|
-
bigNum.fromRed();
|
|
1005
|
-
```
|
|
1006
|
-
|
|
1007
|
-
#### Method fromScriptNum
|
|
1008
|
-
|
|
1009
|
-
Creates a BigNumber from the format used in Bitcoin scripts.
|
|
1010
|
-
|
|
1011
|
-
```ts
|
|
1012
|
-
static fromScriptNum(num: number[], requireMinimal?: boolean, maxNumSize?: number): BigNumber
|
|
1013
|
-
```
|
|
1014
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1015
|
-
|
|
1016
|
-
Returns
|
|
1017
|
-
|
|
1018
|
-
Returns a BigNumber equivalent to the number used in a Bitcoin script.
|
|
1019
|
-
|
|
1020
|
-
Argument Details
|
|
1021
|
-
|
|
1022
|
-
+ **num**
|
|
1023
|
-
+ The number in the format used in Bitcoin scripts.
|
|
1024
|
-
+ **requireMinimal**
|
|
1025
|
-
+ If true, non-minimally encoded values will throw an error.
|
|
1026
|
-
+ **maxNumSize**
|
|
1027
|
-
+ The maximum allowed size for the number. If not provided, defaults to 4.
|
|
1028
|
-
|
|
1029
|
-
Throws
|
|
1030
|
-
|
|
1031
|
-
Will throw an error if `requireMinimal` is `true` and the value is non-minimally encoded. Will throw an error if number length is greater than `maxNumSize`.
|
|
1032
|
-
|
|
1033
|
-
Example
|
|
1034
|
-
|
|
1035
|
-
```ts
|
|
1036
|
-
const num = [0x02, 0x01]
|
|
1037
|
-
const bigNumber = BigNumber.fromScriptNum(num, true, 5)
|
|
1038
|
-
```
|
|
1039
|
-
|
|
1040
|
-
#### Method fromSm
|
|
1041
|
-
|
|
1042
|
-
Creates a BigNumber from a signed magnitude number.
|
|
1043
|
-
|
|
1044
|
-
```ts
|
|
1045
|
-
static fromSm(num: number[], endian: "big" | "little" = "big"): BigNumber
|
|
1046
|
-
```
|
|
1047
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1048
|
-
|
|
1049
|
-
Returns
|
|
1050
|
-
|
|
1051
|
-
Returns a BigNumber equivalent to the signed magnitude number interpreted with specified endianess.
|
|
1052
|
-
|
|
1053
|
-
Argument Details
|
|
1054
|
-
|
|
1055
|
-
+ **num**
|
|
1056
|
-
+ The signed magnitude number to convert to a BigNumber.
|
|
1057
|
-
+ **endian**
|
|
1058
|
-
+ Defines endianess. If not provided, big endian is assumed.
|
|
1059
|
-
|
|
1060
|
-
Example
|
|
1061
|
-
|
|
1062
|
-
```ts
|
|
1063
|
-
const num = [0x81]
|
|
1064
|
-
const bigNumber = BigNumber.fromSm(num, { endian: 'little' }); // equivalent to BigNumber from '-1'
|
|
1065
|
-
```
|
|
1066
|
-
|
|
1067
|
-
#### Method fromString
|
|
1068
|
-
|
|
1069
|
-
Creates a BigNumber from a string, considering an optional base.
|
|
1070
|
-
|
|
1071
|
-
```ts
|
|
1072
|
-
static fromString(str: string, base?: number | "hex"): BigNumber
|
|
1073
|
-
```
|
|
1074
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1075
|
-
|
|
1076
|
-
Returns
|
|
1077
|
-
|
|
1078
|
-
Returns a BigNumber equivalent to the string after conversion from the specified base.
|
|
1079
|
-
|
|
1080
|
-
Argument Details
|
|
1081
|
-
|
|
1082
|
-
+ **str**
|
|
1083
|
-
+ The string to create a BigNumber from.
|
|
1084
|
-
+ **base**
|
|
1085
|
-
+ The base used for conversion. If not provided, base 10 is assumed.
|
|
1086
|
-
|
|
1087
|
-
Example
|
|
1088
|
-
|
|
1089
|
-
```ts
|
|
1090
|
-
const str = '1234';
|
|
1091
|
-
const bigNumber = BigNumber.fromString(str, 16);
|
|
1092
|
-
```
|
|
1093
|
-
|
|
1094
|
-
#### Method fromTwos
|
|
1095
|
-
|
|
1096
|
-
Converts this big number from two's complement with a specified bit width.
|
|
1097
|
-
|
|
1098
|
-
```ts
|
|
1099
|
-
fromTwos(width: number): BigNumber
|
|
1100
|
-
```
|
|
1101
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1102
|
-
|
|
1103
|
-
Returns
|
|
1104
|
-
|
|
1105
|
-
Returns the big number converted from two's complement.
|
|
1106
|
-
|
|
1107
|
-
Argument Details
|
|
1108
|
-
|
|
1109
|
-
+ **width**
|
|
1110
|
-
+ The bit width.
|
|
1111
|
-
|
|
1112
|
-
Example
|
|
1113
|
-
|
|
1114
|
-
```ts
|
|
1115
|
-
const BigNumber = require("./BigNumber");
|
|
1116
|
-
const bn = new BigNumber('-1234');
|
|
1117
|
-
const fromTwos = bn.fromTwos(16);
|
|
1118
|
-
```
|
|
1119
|
-
|
|
1120
|
-
#### Method gcd
|
|
1121
|
-
|
|
1122
|
-
Computes and returns the greatest common divisor (GCD) of this BigNumber and the provided BigNumber.
|
|
1123
|
-
|
|
1124
|
-
```ts
|
|
1125
|
-
gcd(num: BigNumber): BigNumber
|
|
1126
|
-
```
|
|
1127
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1128
|
-
|
|
1129
|
-
Returns
|
|
1130
|
-
|
|
1131
|
-
The GCD of this BigNumber and the provided BigNumber.
|
|
1132
|
-
|
|
1133
|
-
Argument Details
|
|
1134
|
-
|
|
1135
|
-
+ **num**
|
|
1136
|
-
+ The BigNumber with which to compute the GCD.
|
|
1137
|
-
|
|
1138
|
-
Example
|
|
1139
|
-
|
|
1140
|
-
```ts
|
|
1141
|
-
let a = new BigNumber(48);
|
|
1142
|
-
let b = new BigNumber(18);
|
|
1143
|
-
let gcd = a.gcd(b);
|
|
1144
|
-
```
|
|
1145
|
-
|
|
1146
|
-
#### Method gt
|
|
1147
|
-
|
|
1148
|
-
Checks if this BigNumber instance is greater than another BigNumber.
|
|
1149
|
-
|
|
1150
|
-
```ts
|
|
1151
|
-
gt(num: BigNumber): boolean
|
|
1152
|
-
```
|
|
1153
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1154
|
-
|
|
1155
|
-
Returns
|
|
1156
|
-
|
|
1157
|
-
Returns true if this BigNumber is greater than the other BigNumber, false otherwise.
|
|
1158
|
-
|
|
1159
|
-
Argument Details
|
|
1160
|
-
|
|
1161
|
-
+ **num**
|
|
1162
|
-
+ The BigNumber to compare with.
|
|
1163
|
-
|
|
1164
|
-
Example
|
|
1165
|
-
|
|
1166
|
-
```ts
|
|
1167
|
-
let bigNumber1 = new BigNumber('2345');
|
|
1168
|
-
let bigNumber2 = new BigNumber('1234');
|
|
1169
|
-
let isGreater = bigNumber1.gt(bigNumber2); // Returns true
|
|
1170
|
-
```
|
|
1171
|
-
|
|
1172
|
-
#### Method gte
|
|
1173
|
-
|
|
1174
|
-
Checks if this BigNumber instance is greater than or equal to another BigNumber.
|
|
1175
|
-
|
|
1176
|
-
```ts
|
|
1177
|
-
gte(num: BigNumber): boolean
|
|
1178
|
-
```
|
|
1179
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1180
|
-
|
|
1181
|
-
Returns
|
|
1182
|
-
|
|
1183
|
-
Returns true if this BigNumber is greater than or equal to the other BigNumber, false otherwise.
|
|
1184
|
-
|
|
1185
|
-
Argument Details
|
|
1186
|
-
|
|
1187
|
-
+ **num**
|
|
1188
|
-
+ The BigNumber to compare with.
|
|
1189
|
-
|
|
1190
|
-
Example
|
|
1191
|
-
|
|
1192
|
-
```ts
|
|
1193
|
-
let bigNumber1 = new BigNumber('1234');
|
|
1194
|
-
let bigNumber2 = new BigNumber('1234');
|
|
1195
|
-
let isGreaterOrEqual = bigNumber1.gte(bigNumber2); // Returns true
|
|
1196
|
-
```
|
|
1197
|
-
|
|
1198
|
-
#### Method gten
|
|
1199
|
-
|
|
1200
|
-
Checks if this BigNumber instance is greater than or equal to a number.
|
|
1201
|
-
|
|
1202
|
-
```ts
|
|
1203
|
-
gten(num: number): boolean
|
|
1204
|
-
```
|
|
1205
|
-
|
|
1206
|
-
Returns
|
|
1207
|
-
|
|
1208
|
-
Returns true if this BigNumber is greater than or equal to the number, false otherwise.
|
|
1209
|
-
|
|
1210
|
-
Argument Details
|
|
1211
|
-
|
|
1212
|
-
+ **num**
|
|
1213
|
-
+ The number to compare with.
|
|
1214
|
-
|
|
1215
|
-
Example
|
|
1216
|
-
|
|
1217
|
-
```ts
|
|
1218
|
-
let bigNumber = new BigNumber('1234');
|
|
1219
|
-
let isGreaterOrEqual = bigNumber.gten(1234); // Returns true
|
|
1220
|
-
```
|
|
1221
|
-
|
|
1222
|
-
#### Method gtn
|
|
1223
|
-
|
|
1224
|
-
Checks if this BigNumber instance is greater than a number.
|
|
1225
|
-
|
|
1226
|
-
```ts
|
|
1227
|
-
gtn(num: number): boolean
|
|
1228
|
-
```
|
|
1229
|
-
|
|
1230
|
-
Returns
|
|
1231
|
-
|
|
1232
|
-
Returns true if this BigNumber is greater than the number, false otherwise.
|
|
1233
|
-
|
|
1234
|
-
Argument Details
|
|
1235
|
-
|
|
1236
|
-
+ **num**
|
|
1237
|
-
+ The number to compare with.
|
|
1238
|
-
|
|
1239
|
-
Example
|
|
1240
|
-
|
|
1241
|
-
```ts
|
|
1242
|
-
let bigNumber = new BigNumber('2345');
|
|
1243
|
-
let isGreater = bigNumber.gtn(1234); // Returns true
|
|
1244
|
-
```
|
|
1245
|
-
|
|
1246
|
-
#### Method iabs
|
|
1247
|
-
|
|
1248
|
-
Performs an in-place operation to make the BigNumber an absolute value.
|
|
1249
|
-
|
|
1250
|
-
```ts
|
|
1251
|
-
iabs(): this
|
|
1252
|
-
```
|
|
1253
|
-
|
|
1254
|
-
Returns
|
|
1255
|
-
|
|
1256
|
-
Returns the BigNumber as an absolute value.
|
|
1257
|
-
|
|
1258
|
-
Example
|
|
1259
|
-
|
|
1260
|
-
```ts
|
|
1261
|
-
const myNumber = new BigNumber(-50);
|
|
1262
|
-
myNumber.iabs(); // myNumber becomes 50.
|
|
1263
|
-
```
|
|
1264
|
-
|
|
1265
|
-
#### Method iadd
|
|
1266
|
-
|
|
1267
|
-
Add `num` to `this` BigNumber in-place.
|
|
1268
|
-
|
|
1269
|
-
```ts
|
|
1270
|
-
iadd(num: BigNumber): this
|
|
1271
|
-
```
|
|
1272
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1273
|
-
|
|
1274
|
-
Returns
|
|
1275
|
-
|
|
1276
|
-
Returns the BigNumber after performing the addition.
|
|
1277
|
-
|
|
1278
|
-
Argument Details
|
|
1279
|
-
|
|
1280
|
-
+ **num**
|
|
1281
|
-
+ The BigNumber to add to `this` BigNumber.
|
|
1282
|
-
|
|
1283
|
-
Example
|
|
1284
|
-
|
|
1285
|
-
```ts
|
|
1286
|
-
const num1 = new BigNumber('10');
|
|
1287
|
-
num1.iadd(new BigNumber('20'));
|
|
1288
|
-
console.log(num1.toString());
|
|
1289
|
-
```
|
|
1290
|
-
|
|
1291
|
-
#### Method iaddn
|
|
1292
|
-
|
|
1293
|
-
Performs an in-place addition of a plain number to the BigNumber.
|
|
1294
|
-
|
|
1295
|
-
```ts
|
|
1296
|
-
iaddn(num: number): BigNumber
|
|
1297
|
-
```
|
|
1298
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1299
|
-
|
|
1300
|
-
Returns
|
|
1301
|
-
|
|
1302
|
-
Returns the BigNumber after the addition.
|
|
1303
|
-
|
|
1304
|
-
Argument Details
|
|
1305
|
-
|
|
1306
|
-
+ **num**
|
|
1307
|
-
+ The plain number to add.
|
|
1308
|
-
|
|
1309
|
-
Throws
|
|
1310
|
-
|
|
1311
|
-
Will throw an error if num is not a number or is larger than 0x4000000.
|
|
1312
|
-
|
|
1313
|
-
Example
|
|
1314
|
-
|
|
1315
|
-
```ts
|
|
1316
|
-
const myNumber = new BigNumber(50);
|
|
1317
|
-
myNumber.iaddn(2); // myNumber becomes 52.
|
|
1318
|
-
```
|
|
1319
|
-
|
|
1320
|
-
#### Method iand
|
|
1321
|
-
|
|
1322
|
-
Performs an in-place operation that does a bitwise AND operation in-place,
|
|
1323
|
-
on the current instance and given BigNumber such that it modifies the current
|
|
1324
|
-
instance only if neither operand is negative. This method is similar to the iuand method but
|
|
1325
|
-
checks for negative values before operation.
|
|
1326
|
-
|
|
1327
|
-
```ts
|
|
1328
|
-
iand(num: BigNumber): BigNumber
|
|
1329
|
-
```
|
|
1330
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1331
|
-
|
|
1332
|
-
Returns
|
|
1333
|
-
|
|
1334
|
-
Returns the current BigNumber instance after performing the bitwise AND operation.
|
|
1335
|
-
|
|
1336
|
-
Argument Details
|
|
1337
|
-
|
|
1338
|
-
+ **num**
|
|
1339
|
-
+ The BigNumber to perform the bitwise AND operation with.
|
|
1340
|
-
|
|
1341
|
-
Example
|
|
1342
|
-
|
|
1343
|
-
```ts
|
|
1344
|
-
const num1 = new BigNumber('10');
|
|
1345
|
-
const num2 = new BigNumber('20');
|
|
1346
|
-
console.log(num1.iand(num2).toString());
|
|
1347
|
-
```
|
|
1348
|
-
|
|
1349
|
-
#### Method idivn
|
|
1350
|
-
|
|
1351
|
-
Performs an in-place division of a `BigNumber` by a primitive number.
|
|
1352
|
-
|
|
1353
|
-
```ts
|
|
1354
|
-
idivn(num: number): BigNumber
|
|
1355
|
-
```
|
|
1356
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1357
|
-
|
|
1358
|
-
Returns
|
|
1359
|
-
|
|
1360
|
-
The `BigNumber` itself after being divided.
|
|
1361
|
-
Note: 'in-place' means that this operation modifies the original `BigNumber`.
|
|
1362
|
-
|
|
1363
|
-
Argument Details
|
|
1364
|
-
|
|
1365
|
-
+ **num**
|
|
1366
|
-
+ The divisor primitive number.
|
|
1367
|
-
|
|
1368
|
-
Example
|
|
1369
|
-
|
|
1370
|
-
```ts
|
|
1371
|
-
const bigNum = new BigNumber('100');
|
|
1372
|
-
const num = 45;
|
|
1373
|
-
bigNum.idivn(num); // the bigNum here directly becomes '2'
|
|
1374
|
-
```
|
|
1375
|
-
|
|
1376
|
-
#### Method imaskn
|
|
1377
|
-
|
|
1378
|
-
Performs an in-place operation to keep only the lower bits of the number.
|
|
1379
|
-
|
|
1380
|
-
```ts
|
|
1381
|
-
imaskn(bits): this
|
|
1382
|
-
```
|
|
1383
|
-
|
|
1384
|
-
Returns
|
|
1385
|
-
|
|
1386
|
-
Returns the BigNumber with only the specified lower bits.
|
|
1387
|
-
|
|
1388
|
-
Argument Details
|
|
1389
|
-
|
|
1390
|
-
+ **bits**
|
|
1391
|
-
+ The number of lower bits to keep.
|
|
1392
|
-
|
|
1393
|
-
Throws
|
|
1394
|
-
|
|
1395
|
-
Will throw an error if bits is not a positive number.
|
|
1396
|
-
|
|
1397
|
-
Will throw an error if initial BigNumber is negative as imaskn only works with positive numbers.
|
|
1398
|
-
|
|
1399
|
-
Example
|
|
1400
|
-
|
|
1401
|
-
```ts
|
|
1402
|
-
const myNumber = new BigNumber(52);
|
|
1403
|
-
myNumber.imaskn(2); // myNumber becomes 0 because lower 2 bits of 52 (110100) are 00.
|
|
1404
|
-
```
|
|
1405
|
-
|
|
1406
|
-
#### Method imul
|
|
1407
|
-
|
|
1408
|
-
Performs an in-place multiplication of the BigNumber instance by a given BigNumber.
|
|
1409
|
-
|
|
1410
|
-
```ts
|
|
1411
|
-
imul(num: BigNumber): BigNumber
|
|
1412
|
-
```
|
|
1413
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1414
|
-
|
|
1415
|
-
Returns
|
|
1416
|
-
|
|
1417
|
-
The BigNumber itself after the multiplication.
|
|
1418
|
-
|
|
1419
|
-
Argument Details
|
|
1420
|
-
|
|
1421
|
-
+ **num**
|
|
1422
|
-
+ The BigNumber to multiply with.
|
|
1423
|
-
|
|
1424
|
-
Example
|
|
1425
|
-
|
|
1426
|
-
```ts
|
|
1427
|
-
const bn1 = new BigNumber('12345');
|
|
1428
|
-
const bn2 = new BigNumber('23456');
|
|
1429
|
-
bn1.imul(bn2);
|
|
1430
|
-
```
|
|
1431
|
-
|
|
1432
|
-
#### Method imuln
|
|
1433
|
-
|
|
1434
|
-
Performs an in-place multiplication of the BigNumber instance by a number.
|
|
1435
|
-
This method asserts the input to be a number less than 0x4000000 to prevent overflowing.
|
|
1436
|
-
If negavtive number is provided, the resulting BigNumber will be inversely negative.
|
|
1437
|
-
|
|
1438
|
-
```ts
|
|
1439
|
-
imuln(num: number): BigNumber
|
|
1440
|
-
```
|
|
1441
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1442
|
-
|
|
1443
|
-
Returns
|
|
1444
|
-
|
|
1445
|
-
The BigNumber itself after the multiplication.
|
|
1446
|
-
|
|
1447
|
-
Argument Details
|
|
1448
|
-
|
|
1449
|
-
+ **num**
|
|
1450
|
-
+ The number to multiply with.
|
|
1451
|
-
|
|
1452
|
-
Example
|
|
1453
|
-
|
|
1454
|
-
```ts
|
|
1455
|
-
const bn = new BigNumber('12345');
|
|
1456
|
-
bn.imuln(23456);
|
|
1457
|
-
```
|
|
1458
|
-
|
|
1459
|
-
#### Method ineg
|
|
1460
|
-
|
|
1461
|
-
Negates the big number in-place.
|
|
1462
|
-
|
|
1463
|
-
```ts
|
|
1464
|
-
ineg(): BigNumber
|
|
1465
|
-
```
|
|
1466
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1467
|
-
|
|
1468
|
-
Returns
|
|
1469
|
-
|
|
1470
|
-
Returns this big number as the negation of itself.
|
|
1471
|
-
|
|
1472
|
-
Example
|
|
1473
|
-
|
|
1474
|
-
```ts
|
|
1475
|
-
const BigNumber = require("./BigNumber");
|
|
1476
|
-
const bn = new BigNumber('1234');
|
|
1477
|
-
bn.ineg(); // bn is now -1234
|
|
1478
|
-
```
|
|
1479
|
-
|
|
1480
|
-
#### Method inotn
|
|
1481
|
-
|
|
1482
|
-
In-place method that performs a bitwise NOT operation on a BigNumber up to a specified bit width.
|
|
1483
|
-
|
|
1484
|
-
```ts
|
|
1485
|
-
inotn(width: number): BigNumber
|
|
1486
|
-
```
|
|
1487
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1488
|
-
|
|
1489
|
-
Returns
|
|
1490
|
-
|
|
1491
|
-
Returns the BigNumber after performing the bitwise NOT operation.
|
|
1492
|
-
|
|
1493
|
-
Argument Details
|
|
1494
|
-
|
|
1495
|
-
+ **width**
|
|
1496
|
-
+ The number of bits to perform the NOT operation on.
|
|
1497
|
-
|
|
1498
|
-
Example
|
|
1499
|
-
|
|
1500
|
-
```ts
|
|
1501
|
-
const num = new BigNumber('42');
|
|
1502
|
-
num.inotn(10);
|
|
1503
|
-
console.log(num.toString());
|
|
1504
|
-
```
|
|
1505
|
-
|
|
1506
|
-
#### Method inspect
|
|
1507
|
-
|
|
1508
|
-
Utility for inspecting the current BigNumber instance. Accompanied with a prefix '<BN: ' or '<BN-R: '.
|
|
1509
|
-
|
|
1510
|
-
```ts
|
|
1511
|
-
inspect(): string
|
|
1512
|
-
```
|
|
1513
|
-
|
|
1514
|
-
Returns
|
|
1515
|
-
|
|
1516
|
-
A string representation to inspect the BigNumber instance.
|
|
1517
|
-
|
|
1518
|
-
Example
|
|
1519
|
-
|
|
1520
|
-
```ts
|
|
1521
|
-
const bn = new BigNumber('123456', 10, 'be');
|
|
1522
|
-
bn.inspect();
|
|
1523
|
-
```
|
|
1524
|
-
|
|
1525
|
-
#### Method invm
|
|
1526
|
-
|
|
1527
|
-
Computes and returns the modular multiplicative inverse of this BigNumber in the field defined by the provided BigNumber.
|
|
1528
|
-
|
|
1529
|
-
```ts
|
|
1530
|
-
invm(num: BigNumber): BigNumber
|
|
1531
|
-
```
|
|
1532
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1533
|
-
|
|
1534
|
-
Returns
|
|
1535
|
-
|
|
1536
|
-
The modular multiplicative inverse of this BigNumber.
|
|
1537
|
-
|
|
1538
|
-
Argument Details
|
|
1539
|
-
|
|
1540
|
-
+ **num**
|
|
1541
|
-
+ The BigNumber that defines the field.
|
|
1542
|
-
|
|
1543
|
-
Example
|
|
1544
|
-
|
|
1545
|
-
```ts
|
|
1546
|
-
let a = new BigNumber(3);
|
|
1547
|
-
let field = new BigNumber(7);
|
|
1548
|
-
let inverse = a.invm(field);
|
|
1549
|
-
```
|
|
1550
|
-
|
|
1551
|
-
#### Method ior
|
|
1552
|
-
|
|
1553
|
-
Performs a bitwise OR operation with another BigNumber, considering
|
|
1554
|
-
that neither of the numbers can be negative. Stores the result in this BigNumber.
|
|
1555
|
-
|
|
1556
|
-
```ts
|
|
1557
|
-
ior(num: BigNumber): BigNumber
|
|
1558
|
-
```
|
|
1559
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1560
|
-
|
|
1561
|
-
Returns
|
|
1562
|
-
|
|
1563
|
-
Returns this BigNumber after performing the bitwise OR operation.
|
|
1564
|
-
|
|
1565
|
-
Argument Details
|
|
1566
|
-
|
|
1567
|
-
+ **num**
|
|
1568
|
-
+ The other BigNumber.
|
|
1569
|
-
|
|
1570
|
-
Example
|
|
1571
|
-
|
|
1572
|
-
```ts
|
|
1573
|
-
const BigNumber = require("./BigNumber");
|
|
1574
|
-
const bn1 = new BigNumber('10'); // binary: 1010
|
|
1575
|
-
const bn2 = new BigNumber('6'); // binary: 0110
|
|
1576
|
-
bn1.ior(bn2); // now, bn1 binary: 1110
|
|
1577
|
-
```
|
|
1578
|
-
|
|
1579
|
-
#### Method isBN
|
|
1580
|
-
|
|
1581
|
-
Checks whether a value is an instance of BigNumber. If not, then checks the features of the input to determine potential compatibility. Regular JS numbers fail this check.
|
|
1582
|
-
|
|
1583
|
-
```ts
|
|
1584
|
-
static isBN(num: any): boolean
|
|
1585
|
-
```
|
|
1586
|
-
|
|
1587
|
-
Returns
|
|
1588
|
-
|
|
1589
|
-
- Returns a boolean value determining whether or not the checked num parameter is a BigNumber.
|
|
1590
|
-
|
|
1591
|
-
Argument Details
|
|
1592
|
-
|
|
1593
|
-
+ **num**
|
|
1594
|
-
+ The value to be checked.
|
|
1595
|
-
|
|
1596
|
-
Example
|
|
1597
|
-
|
|
1598
|
-
```ts
|
|
1599
|
-
const validNum = new BigNumber(5);
|
|
1600
|
-
BigNumber.isBN(validNum); // returns true
|
|
1601
|
-
|
|
1602
|
-
const invalidNum = 5;
|
|
1603
|
-
BigNumber.isBN(invalidNum); // returns false
|
|
1604
|
-
```
|
|
1605
|
-
|
|
1606
|
-
#### Method isEven
|
|
1607
|
-
|
|
1608
|
-
Checks if this BigNumber is even.
|
|
1609
|
-
An even number is an integer which is evenly divisible by two.
|
|
1610
|
-
|
|
1611
|
-
```ts
|
|
1612
|
-
isEven(): boolean
|
|
1613
|
-
```
|
|
1614
|
-
|
|
1615
|
-
Returns
|
|
1616
|
-
|
|
1617
|
-
true if this BigNumber is even, else false.
|
|
1618
|
-
|
|
1619
|
-
Example
|
|
1620
|
-
|
|
1621
|
-
```ts
|
|
1622
|
-
let a = new BigNumber(4);
|
|
1623
|
-
let isEven = a.isEven(); // true
|
|
1624
|
-
```
|
|
1625
|
-
|
|
1626
|
-
#### Method isNeg
|
|
1627
|
-
|
|
1628
|
-
Checks if the big number is negative.
|
|
1629
|
-
|
|
1630
|
-
```ts
|
|
1631
|
-
isNeg(): boolean
|
|
1632
|
-
```
|
|
1633
|
-
|
|
1634
|
-
Returns
|
|
1635
|
-
|
|
1636
|
-
Returns true if the big number is negative, otherwise false.
|
|
1637
|
-
|
|
1638
|
-
Example
|
|
1639
|
-
|
|
1640
|
-
```ts
|
|
1641
|
-
const BigNumber = require("./BigNumber");
|
|
1642
|
-
const bn = new BigNumber('-1234');
|
|
1643
|
-
const isNegative = bn.isNeg(); // true
|
|
1644
|
-
```
|
|
1645
|
-
|
|
1646
|
-
#### Method isOdd
|
|
1647
|
-
|
|
1648
|
-
Checks if this BigNumber is Odd.
|
|
1649
|
-
An odd number is an integer which is not evenly divisible by two.
|
|
1650
|
-
|
|
1651
|
-
```ts
|
|
1652
|
-
isOdd(): boolean
|
|
1653
|
-
```
|
|
1654
|
-
|
|
1655
|
-
Returns
|
|
1656
|
-
|
|
1657
|
-
true if this BigNumber is Odd, else false.
|
|
1658
|
-
|
|
1659
|
-
Example
|
|
1660
|
-
|
|
1661
|
-
```ts
|
|
1662
|
-
let a = new BigNumber(3);
|
|
1663
|
-
let isOdd = a.isOdd(); // true
|
|
1664
|
-
```
|
|
1665
|
-
|
|
1666
|
-
#### Method isZero
|
|
1667
|
-
|
|
1668
|
-
Checks if this BigNumber is Zero.
|
|
1669
|
-
A BigNumber is zero if it only contains one word and that word is 0.
|
|
1670
|
-
|
|
1671
|
-
```ts
|
|
1672
|
-
isZero(): boolean
|
|
1673
|
-
```
|
|
1674
|
-
|
|
1675
|
-
Returns
|
|
1676
|
-
|
|
1677
|
-
true if this BigNumber is Zero, else false.
|
|
1678
|
-
|
|
1679
|
-
Example
|
|
1680
|
-
|
|
1681
|
-
```ts
|
|
1682
|
-
let a = new BigNumber(0);
|
|
1683
|
-
let isZero = a.isZero(); // true
|
|
1684
|
-
```
|
|
1685
|
-
|
|
1686
|
-
#### Method ishln
|
|
1687
|
-
|
|
1688
|
-
Performs an in-place left shift operation on the BigNumber instance only if it is non-negative.
|
|
1689
|
-
|
|
1690
|
-
```ts
|
|
1691
|
-
ishln(bits: number): this
|
|
1692
|
-
```
|
|
1693
|
-
|
|
1694
|
-
Returns
|
|
1695
|
-
|
|
1696
|
-
The BigNumber instance after performing the shift operation.
|
|
1697
|
-
|
|
1698
|
-
Argument Details
|
|
1699
|
-
|
|
1700
|
-
+ **bits**
|
|
1701
|
-
+ The number of positions to shift.
|
|
1702
|
-
|
|
1703
|
-
Example
|
|
1704
|
-
|
|
1705
|
-
```ts
|
|
1706
|
-
let myNumber = new BigNumber(4);
|
|
1707
|
-
myNumber.ishln(2); // Returns BigNumber of value 16
|
|
1708
|
-
```
|
|
1709
|
-
|
|
1710
|
-
#### Method ishrn
|
|
1711
|
-
|
|
1712
|
-
Performs an in-place right shift operation on the BigNumber instance only if it is non-negative.
|
|
1713
|
-
|
|
1714
|
-
```ts
|
|
1715
|
-
ishrn(bits, hint?, extended?): this
|
|
1716
|
-
```
|
|
1717
|
-
|
|
1718
|
-
Returns
|
|
1719
|
-
|
|
1720
|
-
The BigNumber instance after performing the shift operation.
|
|
1721
|
-
|
|
1722
|
-
Argument Details
|
|
1723
|
-
|
|
1724
|
-
+ **bits**
|
|
1725
|
-
+ The number of positions to shift.
|
|
1726
|
-
+ **hint**
|
|
1727
|
-
+ Lowest bit before trailing zeroes.
|
|
1728
|
-
+ **extended**
|
|
1729
|
-
+ To be filled with the bits that are shifted out.
|
|
1730
|
-
|
|
1731
|
-
Example
|
|
1732
|
-
|
|
1733
|
-
```ts
|
|
1734
|
-
let myNumber = new BigNumber(16);
|
|
1735
|
-
myNumber.ishrn(2); // Returns BigNumber of value 4
|
|
1736
|
-
```
|
|
1737
|
-
|
|
1738
|
-
#### Method isqr
|
|
1739
|
-
|
|
1740
|
-
Performs in-place multiplication of the BigNumber instance by itself.
|
|
1741
|
-
|
|
1742
|
-
```ts
|
|
1743
|
-
isqr(): BigNumber
|
|
1744
|
-
```
|
|
1745
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1746
|
-
|
|
1747
|
-
Returns
|
|
1748
|
-
|
|
1749
|
-
The result of multiplying the BigNumber instance by itself.
|
|
1750
|
-
|
|
1751
|
-
Example
|
|
1752
|
-
|
|
1753
|
-
```ts
|
|
1754
|
-
let myNumber = new BigNumber(4);
|
|
1755
|
-
myNumber.isqr(); // Returns BigNumber of value 16
|
|
1756
|
-
```
|
|
1757
|
-
|
|
1758
|
-
#### Method isub
|
|
1759
|
-
|
|
1760
|
-
Subtract `num` from `this` BigNumber in-place.
|
|
1761
|
-
|
|
1762
|
-
```ts
|
|
1763
|
-
isub(num: BigNumber): BigNumber
|
|
1764
|
-
```
|
|
1765
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1766
|
-
|
|
1767
|
-
Returns
|
|
1768
|
-
|
|
1769
|
-
Returns the BigNumber after performing the subtraction.
|
|
1770
|
-
|
|
1771
|
-
Argument Details
|
|
1772
|
-
|
|
1773
|
-
+ **num**
|
|
1774
|
-
+ The BigNumber to be subtracted from `this` BigNumber.
|
|
1775
|
-
|
|
1776
|
-
Example
|
|
1777
|
-
|
|
1778
|
-
```ts
|
|
1779
|
-
const num1 = new BigNumber('20');
|
|
1780
|
-
num1.isub(new BigNumber('10'));
|
|
1781
|
-
console.log(num1.toString());
|
|
1782
|
-
```
|
|
1783
|
-
|
|
1784
|
-
#### Method isubn
|
|
1785
|
-
|
|
1786
|
-
Performs an in-place subtraction of a plain number from the BigNumber.
|
|
1787
|
-
|
|
1788
|
-
```ts
|
|
1789
|
-
isubn(num: number): BigNumber
|
|
1790
|
-
```
|
|
1791
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1792
|
-
|
|
1793
|
-
Returns
|
|
1794
|
-
|
|
1795
|
-
Returns the BigNumber after the subtraction.
|
|
1796
|
-
|
|
1797
|
-
Argument Details
|
|
1798
|
-
|
|
1799
|
-
+ **num**
|
|
1800
|
-
+ The plain number to subtract.
|
|
1801
|
-
|
|
1802
|
-
Throws
|
|
1803
|
-
|
|
1804
|
-
Will throw an error if num is not a number or is larger than 0x4000000.
|
|
1805
|
-
|
|
1806
|
-
Example
|
|
1807
|
-
|
|
1808
|
-
```ts
|
|
1809
|
-
const myNumber = new BigNumber(52);
|
|
1810
|
-
myNumber.isubn(2); // myNumber becomes 50.
|
|
1811
|
-
```
|
|
1812
|
-
|
|
1813
|
-
#### Method iuand
|
|
1814
|
-
|
|
1815
|
-
Performs a bitwise AND operation in-place(this method changes the calling object)
|
|
1816
|
-
on the current instance and given BigNumber such that it modifies the current
|
|
1817
|
-
instance and keeps the bits set in the result only if the corresponding bit is set
|
|
1818
|
-
in both operands.
|
|
1819
|
-
|
|
1820
|
-
```ts
|
|
1821
|
-
iuand(num: BigNumber): BigNumber
|
|
1822
|
-
```
|
|
1823
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1824
|
-
|
|
1825
|
-
Returns
|
|
1826
|
-
|
|
1827
|
-
Returns the current BigNumber instance after performing the bitwise AND operation.
|
|
1828
|
-
|
|
1829
|
-
Argument Details
|
|
1830
|
-
|
|
1831
|
-
+ **num**
|
|
1832
|
-
+ The BigNumber to perform the bitwise AND operation with.
|
|
1833
|
-
|
|
1834
|
-
Example
|
|
1835
|
-
|
|
1836
|
-
```ts
|
|
1837
|
-
const num1 = new BigNumber('10');
|
|
1838
|
-
const num2 = new BigNumber('20');
|
|
1839
|
-
console.log(num1.iuand(num2).toString());
|
|
1840
|
-
```
|
|
1841
|
-
|
|
1842
|
-
#### Method iuor
|
|
1843
|
-
|
|
1844
|
-
Performs a bitwise OR operation with another BigNumber and stores
|
|
1845
|
-
the result in this BigNumber.
|
|
1846
|
-
|
|
1847
|
-
```ts
|
|
1848
|
-
iuor(num: BigNumber): BigNumber
|
|
1849
|
-
```
|
|
1850
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1851
|
-
|
|
1852
|
-
Returns
|
|
1853
|
-
|
|
1854
|
-
Returns this BigNumber after performing the bitwise OR operation.
|
|
1855
|
-
|
|
1856
|
-
Argument Details
|
|
1857
|
-
|
|
1858
|
-
+ **num**
|
|
1859
|
-
+ The other BigNumber.
|
|
1860
|
-
|
|
1861
|
-
Example
|
|
1862
|
-
|
|
1863
|
-
```ts
|
|
1864
|
-
const BigNumber = require("./BigNumber");
|
|
1865
|
-
const bn1 = new BigNumber('10'); // binary: 1010
|
|
1866
|
-
const bn2 = new(num: BigNumber): BigNumber BigNumber('6'); // binary: 0110
|
|
1867
|
-
bn1.iuor(bn2); // now, bn1 binary: 1110
|
|
1868
|
-
```
|
|
1869
|
-
|
|
1870
|
-
#### Method iushln
|
|
1871
|
-
|
|
1872
|
-
Performs in-place bitwise left shift operation on the BigNumber instance.
|
|
1873
|
-
|
|
1874
|
-
```ts
|
|
1875
|
-
iushln(bits: number): this
|
|
1876
|
-
```
|
|
1877
|
-
|
|
1878
|
-
Returns
|
|
1879
|
-
|
|
1880
|
-
The BigNumber instance after performing the shift operation.
|
|
1881
|
-
|
|
1882
|
-
Argument Details
|
|
1883
|
-
|
|
1884
|
-
+ **bits**
|
|
1885
|
-
+ The number of positions to shift.
|
|
1886
|
-
|
|
1887
|
-
Example
|
|
1888
|
-
|
|
1889
|
-
```ts
|
|
1890
|
-
let myNumber = new BigNumber(4);
|
|
1891
|
-
myNumber.iushln(2); // Returns BigNumber of value 16
|
|
1892
|
-
```
|
|
1893
|
-
|
|
1894
|
-
#### Method iushrn
|
|
1895
|
-
|
|
1896
|
-
Performs an in-place unsigned bitwise right shift operation on the BigNumber instance.
|
|
1897
|
-
|
|
1898
|
-
```ts
|
|
1899
|
-
iushrn(bits: number, hint?: number, extended?: BigNumber): this
|
|
1900
|
-
```
|
|
1901
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1902
|
-
|
|
1903
|
-
Returns
|
|
1904
|
-
|
|
1905
|
-
The BigNumber instance after performing the shift operation.
|
|
1906
|
-
|
|
1907
|
-
Argument Details
|
|
1908
|
-
|
|
1909
|
-
+ **bits**
|
|
1910
|
-
+ The number of positions to shift.
|
|
1911
|
-
+ **hint**
|
|
1912
|
-
+ Lowest bit before trailing zeroes.
|
|
1913
|
-
+ **extended**
|
|
1914
|
-
+ To be filled with the bits that are shifted out.
|
|
1915
|
-
|
|
1916
|
-
Example
|
|
1917
|
-
|
|
1918
|
-
```ts
|
|
1919
|
-
let myNumber = new BigNumber(16);
|
|
1920
|
-
myNumber.iushrn(2); // Returns BigNumber of value 4
|
|
1921
|
-
```
|
|
1922
|
-
|
|
1923
|
-
#### Method iuxor
|
|
1924
|
-
|
|
1925
|
-
Modifies the current instance by performing a bitwise XOR operation
|
|
1926
|
-
in-place with the provided BigNumber. It keeps the bits set in the result only if the
|
|
1927
|
-
corresponding bits in the operands are different.
|
|
1928
|
-
|
|
1929
|
-
```ts
|
|
1930
|
-
iuxor(num: BigNumber): this
|
|
1931
|
-
```
|
|
1932
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1933
|
-
|
|
1934
|
-
Returns
|
|
1935
|
-
|
|
1936
|
-
Returns the current BigNumber instance after performing the bitwise XOR operation.
|
|
1937
|
-
|
|
1938
|
-
Argument Details
|
|
1939
|
-
|
|
1940
|
-
+ **num**
|
|
1941
|
-
+ The BigNumber to perform the bitwise XOR operation with.
|
|
1942
|
-
|
|
1943
|
-
Example
|
|
1944
|
-
|
|
1945
|
-
```ts
|
|
1946
|
-
const num1 = new BigNumber('10');
|
|
1947
|
-
const num2 = new BigNumber('20');
|
|
1948
|
-
console.log(num1.iuxor(num2).toString());
|
|
1949
|
-
```
|
|
1950
|
-
|
|
1951
|
-
#### Method ixor
|
|
1952
|
-
|
|
1953
|
-
Performs an in-place operation that does a bitwise XOR operation in-place,
|
|
1954
|
-
on the current instance and given BigNumber such that it modifies the current
|
|
1955
|
-
instance only if neither operand is negative. This method is similar to the iuxor method but
|
|
1956
|
-
checks for negative values before operation.
|
|
1957
|
-
|
|
1958
|
-
```ts
|
|
1959
|
-
ixor(num: BigNumber): this
|
|
1960
|
-
```
|
|
1961
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1962
|
-
|
|
1963
|
-
Returns
|
|
1964
|
-
|
|
1965
|
-
Returns the current BigNumber instance after performing the bitwise XOR operation.
|
|
1966
|
-
|
|
1967
|
-
Argument Details
|
|
1968
|
-
|
|
1969
|
-
+ **num**
|
|
1970
|
-
+ The BigNumber to perform the bitwise XOR operation with.
|
|
1971
|
-
|
|
1972
|
-
Example
|
|
1973
|
-
|
|
1974
|
-
```ts
|
|
1975
|
-
const num1 = new BigNumber('10');
|
|
1976
|
-
const num2 = new BigNumber('20');
|
|
1977
|
-
console.log(num1.ixor(num2).toString());
|
|
1978
|
-
```
|
|
1979
|
-
|
|
1980
|
-
#### Method lt
|
|
1981
|
-
|
|
1982
|
-
Checks if this BigNumber instance is less than another BigNumber.
|
|
1983
|
-
|
|
1984
|
-
```ts
|
|
1985
|
-
lt(num: BigNumber): boolean
|
|
1986
|
-
```
|
|
1987
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
1988
|
-
|
|
1989
|
-
Returns
|
|
1990
|
-
|
|
1991
|
-
Returns true if this BigNumber is less than the other BigNumber, false otherwise.
|
|
1992
|
-
|
|
1993
|
-
Argument Details
|
|
1994
|
-
|
|
1995
|
-
+ **num**
|
|
1996
|
-
+ The BigNumber to compare with.
|
|
1997
|
-
|
|
1998
|
-
Example
|
|
1999
|
-
|
|
2000
|
-
```ts
|
|
2001
|
-
let bigNumber1 = new BigNumber('1234');
|
|
2002
|
-
let bigNumber2 = new BigNumber('2345');
|
|
2003
|
-
let isLess = bigNumber1.lt(bigNumber2); // Returns true
|
|
2004
|
-
```
|
|
2005
|
-
|
|
2006
|
-
#### Method lte
|
|
2007
|
-
|
|
2008
|
-
Checks if this BigNumber instance is less than or equal to another BigNumber.
|
|
2009
|
-
|
|
2010
|
-
```ts
|
|
2011
|
-
lte(num: BigNumber): boolean
|
|
2012
|
-
```
|
|
2013
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2014
|
-
|
|
2015
|
-
Returns
|
|
2016
|
-
|
|
2017
|
-
Returns true if this BigNumber is less than or equal to the other BigNumber, false otherwise.
|
|
2018
|
-
|
|
2019
|
-
Argument Details
|
|
2020
|
-
|
|
2021
|
-
+ **num**
|
|
2022
|
-
+ The BigNumber to compare with.
|
|
2023
|
-
|
|
2024
|
-
Example
|
|
2025
|
-
|
|
2026
|
-
```ts
|
|
2027
|
-
let bigNumber1 = new BigNumber('2345');
|
|
2028
|
-
let bigNumber2 = new BigNumber('2345');
|
|
2029
|
-
let isLessOrEqual = bigNumber1.lte(bigNumber2); // Returns true
|
|
2030
|
-
```
|
|
2031
|
-
|
|
2032
|
-
#### Method lten
|
|
2033
|
-
|
|
2034
|
-
Checks if this BigNumber instance is less than or equal to a number.
|
|
2035
|
-
|
|
2036
|
-
```ts
|
|
2037
|
-
lten(num: number): boolean
|
|
2038
|
-
```
|
|
2039
|
-
|
|
2040
|
-
Returns
|
|
2041
|
-
|
|
2042
|
-
Returns true if this BigNumber is less than or equal to the number, false otherwise.
|
|
2043
|
-
|
|
2044
|
-
Argument Details
|
|
2045
|
-
|
|
2046
|
-
+ **num**
|
|
2047
|
-
+ The number to compare with.
|
|
2048
|
-
|
|
2049
|
-
Example
|
|
2050
|
-
|
|
2051
|
-
```ts
|
|
2052
|
-
let bigNumber = new BigNumber('2345');
|
|
2053
|
-
let isLessOrEqual = bigNumber.lten(2345); // Returns true
|
|
2054
|
-
```
|
|
2055
|
-
|
|
2056
|
-
#### Method ltn
|
|
2057
|
-
|
|
2058
|
-
Checks if this BigNumber instance is less than a number.
|
|
2059
|
-
|
|
2060
|
-
```ts
|
|
2061
|
-
ltn(num: number): boolean
|
|
2062
|
-
```
|
|
2063
|
-
|
|
2064
|
-
Returns
|
|
2065
|
-
|
|
2066
|
-
Returns true if this BigNumber is less than the number, false otherwise.
|
|
2067
|
-
|
|
2068
|
-
Argument Details
|
|
2069
|
-
|
|
2070
|
-
+ **num**
|
|
2071
|
-
+ The number to compare with.
|
|
2072
|
-
|
|
2073
|
-
Example
|
|
2074
|
-
|
|
2075
|
-
```ts
|
|
2076
|
-
let bigNumber = new BigNumber('1234');
|
|
2077
|
-
let isLess = bigNumber.ltn(2345); // Returns true
|
|
2078
|
-
```
|
|
2079
|
-
|
|
2080
|
-
#### Method maskn
|
|
2081
|
-
|
|
2082
|
-
Returns a new BigNumber that keeps only the lower bits of the original number.
|
|
2083
|
-
|
|
2084
|
-
```ts
|
|
2085
|
-
maskn(bits): BigNumber
|
|
2086
|
-
```
|
|
2087
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2088
|
-
|
|
2089
|
-
Returns
|
|
2090
|
-
|
|
2091
|
-
Returns a new BigNumber with only the specified lower bits of the original number.
|
|
2092
|
-
|
|
2093
|
-
Argument Details
|
|
2094
|
-
|
|
2095
|
-
+ **bits**
|
|
2096
|
-
+ The number of lower bits to keep.
|
|
2097
|
-
|
|
2098
|
-
Example
|
|
2099
|
-
|
|
2100
|
-
```ts
|
|
2101
|
-
const myNumber = new BigNumber(52);
|
|
2102
|
-
const newNumber = myNumber.maskn(2); // newNumber becomes 0, myNumber doesn't change.
|
|
2103
|
-
```
|
|
2104
|
-
|
|
2105
|
-
#### Method max
|
|
2106
|
-
|
|
2107
|
-
Returns the bigger value between two BigNumbers
|
|
2108
|
-
|
|
2109
|
-
```ts
|
|
2110
|
-
static max(left: BigNumber, right: BigNumber): BigNumber
|
|
2111
|
-
```
|
|
2112
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2113
|
-
|
|
2114
|
-
Returns
|
|
2115
|
-
|
|
2116
|
-
- Returns the bigger BigNumber between left and right.
|
|
2117
|
-
|
|
2118
|
-
Argument Details
|
|
2119
|
-
|
|
2120
|
-
+ **left**
|
|
2121
|
-
+ The first BigNumber to be compared.
|
|
2122
|
-
+ **right**
|
|
2123
|
-
+ The second BigNumber to be compared.
|
|
2124
|
-
|
|
2125
|
-
Example
|
|
2126
|
-
|
|
2127
|
-
```ts
|
|
2128
|
-
const bn1 = new BigNumber(5);
|
|
2129
|
-
const bn2 = new BigNumber(10);
|
|
2130
|
-
BigNumber.max(bn1, bn2); // returns bn2
|
|
2131
|
-
```
|
|
2132
|
-
|
|
2133
|
-
#### Method min
|
|
2134
|
-
|
|
2135
|
-
Returns the smaller value between two BigNumbers
|
|
2136
|
-
|
|
2137
|
-
```ts
|
|
2138
|
-
static min(left: BigNumber, right: BigNumber): BigNumber
|
|
2139
|
-
```
|
|
2140
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2141
|
-
|
|
2142
|
-
Returns
|
|
2143
|
-
|
|
2144
|
-
- Returns the smaller value between left and right.
|
|
2145
|
-
|
|
2146
|
-
Argument Details
|
|
2147
|
-
|
|
2148
|
-
+ **left**
|
|
2149
|
-
+ The first BigNumber to be compared.
|
|
2150
|
-
+ **right**
|
|
2151
|
-
+ The second BigNumber to be compared.
|
|
2152
|
-
|
|
2153
|
-
Example
|
|
2154
|
-
|
|
2155
|
-
```ts
|
|
2156
|
-
const bn1 = new BigNumber(5);
|
|
2157
|
-
const bn2 = new BigNumber(10);
|
|
2158
|
-
BigNumber.min(bn1, bn2); // returns bn1
|
|
2159
|
-
```
|
|
2160
|
-
|
|
2161
|
-
#### Method mod
|
|
2162
|
-
|
|
2163
|
-
Returns the remainder after division of one `BigNumber` by another `BigNumber`.
|
|
2164
|
-
|
|
2165
|
-
```ts
|
|
2166
|
-
mod(num: BigNumber): BigNumber
|
|
2167
|
-
```
|
|
2168
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2169
|
-
|
|
2170
|
-
Returns
|
|
2171
|
-
|
|
2172
|
-
The remainder `BigNumber` after division.
|
|
2173
|
-
|
|
2174
|
-
Argument Details
|
|
2175
|
-
|
|
2176
|
-
+ **num**
|
|
2177
|
-
+ The divisor `BigNumber`.
|
|
2178
|
-
|
|
2179
|
-
Example
|
|
2180
|
-
|
|
2181
|
-
```ts
|
|
2182
|
-
const bigNum1 = new BigNumber('100');
|
|
2183
|
-
const bigNum2 = new BigNumber('45');
|
|
2184
|
-
const remainder = bigNum1.mod(bigNum2); // remainder here would be '10'
|
|
2185
|
-
```
|
|
2186
|
-
|
|
2187
|
-
#### Method modrn
|
|
2188
|
-
|
|
2189
|
-
Returns the remainder after division of a `BigNumber` by a primitive number.
|
|
2190
|
-
|
|
2191
|
-
```ts
|
|
2192
|
-
modrn(num: number): number
|
|
2193
|
-
```
|
|
2194
|
-
|
|
2195
|
-
Returns
|
|
2196
|
-
|
|
2197
|
-
The remainder number after division.
|
|
2198
|
-
|
|
2199
|
-
Argument Details
|
|
2200
|
-
|
|
2201
|
-
+ **num**
|
|
2202
|
-
+ The divisor primitive number.
|
|
2203
|
-
|
|
2204
|
-
Example
|
|
2205
|
-
|
|
2206
|
-
```ts
|
|
2207
|
-
const bigNum = new BigNumber('100');
|
|
2208
|
-
const num = 45;
|
|
2209
|
-
const remainder = bigNum.modrn(num); // remainder here would be '10'
|
|
2210
|
-
```
|
|
2211
|
-
|
|
2212
|
-
#### Method move
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
Directly transfers the attributes of the source BigNumber to the destination BigNumber.
|
|
2216
|
-
|
|
2217
|
-
```ts
|
|
2218
|
-
static move(dest: BigNumber, src: BigNumber): void
|
|
2219
|
-
```
|
|
2220
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2221
|
-
|
|
2222
|
-
Argument Details
|
|
2223
|
-
|
|
2224
|
-
+ **dest**
|
|
2225
|
-
+ The BigNumber that attributes will be moved into.
|
|
2226
|
-
+ **src**
|
|
2227
|
-
+ The BigNumber that attributes will be moved from.
|
|
2228
|
-
|
|
2229
|
-
Example
|
|
2230
|
-
|
|
2231
|
-
```ts
|
|
2232
|
-
const src = new BigNumber('123456', 10, 'be');
|
|
2233
|
-
const dest = new BigNumber();
|
|
2234
|
-
BigNumber.move(dest, src);
|
|
2235
|
-
// dest is now a BigNumber representing 123456
|
|
2236
|
-
```
|
|
2237
|
-
|
|
2238
|
-
#### Method mul
|
|
2239
|
-
|
|
2240
|
-
Performs multiplication between the BigNumber instance and a given BigNumber.
|
|
2241
|
-
It creates a new BigNumber to store the result.
|
|
2242
|
-
|
|
2243
|
-
```ts
|
|
2244
|
-
mul(num: BigNumber): BigNumber
|
|
2245
|
-
```
|
|
2246
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2247
|
-
|
|
2248
|
-
Returns
|
|
2249
|
-
|
|
2250
|
-
The BigNumber resulting from the multiplication operation.
|
|
2251
|
-
|
|
2252
|
-
Argument Details
|
|
2253
|
-
|
|
2254
|
-
+ **num**
|
|
2255
|
-
+ The BigNumber to multiply with.
|
|
2256
|
-
|
|
2257
|
-
Example
|
|
2258
|
-
|
|
2259
|
-
```ts
|
|
2260
|
-
const bn1 = new BigNumber('12345');
|
|
2261
|
-
const bn2 = new BigNumber('23456');
|
|
2262
|
-
const result = bn1.mul(bn2);
|
|
2263
|
-
```
|
|
2264
|
-
|
|
2265
|
-
#### Method mulTo
|
|
2266
|
-
|
|
2267
|
-
Performs multiplication between the BigNumber instance and a given BigNumber.
|
|
2268
|
-
It chooses the multiplication method based on the lengths of the numbers to optimize execution time.
|
|
2269
|
-
|
|
2270
|
-
```ts
|
|
2271
|
-
mulTo(num: BigNumber, out: BigNumber): BigNumber
|
|
2272
|
-
```
|
|
2273
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2274
|
-
|
|
2275
|
-
Returns
|
|
2276
|
-
|
|
2277
|
-
The BigNumber resulting from the multiplication operation.
|
|
2278
|
-
|
|
2279
|
-
Argument Details
|
|
2280
|
-
|
|
2281
|
-
+ **num**
|
|
2282
|
-
+ The BigNumber multiply with.
|
|
2283
|
-
+ **out**
|
|
2284
|
-
+ The BigNumber where to store the result.
|
|
2285
|
-
|
|
2286
|
-
Example
|
|
2287
|
-
|
|
2288
|
-
```ts
|
|
2289
|
-
const bn1 = new BigNumber('12345');
|
|
2290
|
-
const bn2 = new BigNumber('23456');
|
|
2291
|
-
const output = new BigNumber();
|
|
2292
|
-
bn1.mulTo(bn2, output);
|
|
2293
|
-
```
|
|
2294
|
-
|
|
2295
|
-
#### Method muln
|
|
2296
|
-
|
|
2297
|
-
Performs multiplication between the BigNumber instance and a number.
|
|
2298
|
-
It performs the multiplication operation in-place to a cloned BigNumber.
|
|
2299
|
-
|
|
2300
|
-
```ts
|
|
2301
|
-
muln(num: number): BigNumber
|
|
2302
|
-
```
|
|
2303
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2304
|
-
|
|
2305
|
-
Returns
|
|
2306
|
-
|
|
2307
|
-
The resulting BigNumber from the multiplication operation.
|
|
2308
|
-
|
|
2309
|
-
Argument Details
|
|
2310
|
-
|
|
2311
|
-
+ **num**
|
|
2312
|
-
+ The number to multiply with.
|
|
2313
|
-
|
|
2314
|
-
Example
|
|
2315
|
-
|
|
2316
|
-
```ts
|
|
2317
|
-
const bn = new BigNumber('12345');
|
|
2318
|
-
const result = bn.muln(23456);
|
|
2319
|
-
```
|
|
2320
|
-
|
|
2321
|
-
#### Method neg
|
|
2322
|
-
|
|
2323
|
-
Negates the big number and returns a new instance.
|
|
2324
|
-
|
|
2325
|
-
```ts
|
|
2326
|
-
neg(): BigNumber
|
|
2327
|
-
```
|
|
2328
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2329
|
-
|
|
2330
|
-
Returns
|
|
2331
|
-
|
|
2332
|
-
Returns a new BigNumber that is the negation of this big number.
|
|
2333
|
-
|
|
2334
|
-
Example
|
|
2335
|
-
|
|
2336
|
-
```ts
|
|
2337
|
-
const BigNumber = require("./BigNumber");
|
|
2338
|
-
const bn = new BigNumber('1234');
|
|
2339
|
-
const neg = bn.neg(); // -1234
|
|
2340
|
-
```
|
|
2341
|
-
|
|
2342
|
-
#### Method normSign
|
|
2343
|
-
|
|
2344
|
-
Normalizes the sign of the BigNumber. Changes -0 to 0.
|
|
2345
|
-
|
|
2346
|
-
```ts
|
|
2347
|
-
normSign(): this
|
|
2348
|
-
```
|
|
2349
|
-
|
|
2350
|
-
Returns
|
|
2351
|
-
|
|
2352
|
-
The normalized BigNumber instance.
|
|
2353
|
-
|
|
2354
|
-
Example
|
|
2355
|
-
|
|
2356
|
-
```ts
|
|
2357
|
-
const bn = new BigNumber('-0', 10, 'be');
|
|
2358
|
-
bn.normSign();
|
|
2359
|
-
```
|
|
2360
|
-
|
|
2361
|
-
#### Method notn
|
|
2362
|
-
|
|
2363
|
-
Performs a bitwise NOT operation on a BigNumber up to a specified bit width. Returns a new BigNumber.
|
|
2364
|
-
|
|
2365
|
-
```ts
|
|
2366
|
-
notn(width: number): BigNumber
|
|
2367
|
-
```
|
|
2368
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2369
|
-
|
|
2370
|
-
Returns
|
|
2371
|
-
|
|
2372
|
-
Returns a new BigNumber resulting from the bitwise NOT operation.
|
|
2373
|
-
|
|
2374
|
-
Argument Details
|
|
2375
|
-
|
|
2376
|
-
+ **width**
|
|
2377
|
-
+ The number of bits to perform the NOT operation on.
|
|
2378
|
-
|
|
2379
|
-
Example
|
|
2380
|
-
|
|
2381
|
-
```ts
|
|
2382
|
-
const num = new BigNumber('42');
|
|
2383
|
-
const notnResult = num.notn(10);
|
|
2384
|
-
console.log(notnResult.toString());
|
|
2385
|
-
```
|
|
2386
|
-
|
|
2387
|
-
#### Method or
|
|
2388
|
-
|
|
2389
|
-
Performs a bitwise OR operation on the current instance and given
|
|
2390
|
-
BigNumber and returns a new BigNumber, in such a way that if either
|
|
2391
|
-
the corresponding bit in the first operand or the second operand is
|
|
2392
|
-
1, then the output is also 1.
|
|
2393
|
-
|
|
2394
|
-
```ts
|
|
2395
|
-
or(num: BigNumber): BigNumber
|
|
2396
|
-
```
|
|
2397
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2398
|
-
|
|
2399
|
-
Returns
|
|
2400
|
-
|
|
2401
|
-
Returns a new BigNumber resulting from the bitwise OR operation.
|
|
2402
|
-
|
|
2403
|
-
Argument Details
|
|
2404
|
-
|
|
2405
|
-
+ **num**
|
|
2406
|
-
+ The BigNumber to perform the bitwise OR operation with.
|
|
2407
|
-
|
|
2408
|
-
Example
|
|
2409
|
-
|
|
2410
|
-
```ts
|
|
2411
|
-
const num1 = new BigNumber('10');
|
|
2412
|
-
const num2 = new BigNumber('20');
|
|
2413
|
-
console.log(num1.or(num2).toString());
|
|
2414
|
-
```
|
|
2415
|
-
|
|
2416
|
-
#### Method pow
|
|
2417
|
-
|
|
2418
|
-
Raises the BigNumber instance to the power of the specified BigNumber.
|
|
2419
|
-
|
|
2420
|
-
```ts
|
|
2421
|
-
pow(num: BigNumber): BigNumber
|
|
2422
|
-
```
|
|
2423
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2424
|
-
|
|
2425
|
-
Returns
|
|
2426
|
-
|
|
2427
|
-
The result of raising the BigNumber instance to the power of num.
|
|
2428
|
-
|
|
2429
|
-
Argument Details
|
|
2430
|
-
|
|
2431
|
-
+ **num**
|
|
2432
|
-
+ The exponent to raise the BigNumber instance to.
|
|
2433
|
-
|
|
2434
|
-
Example
|
|
2435
|
-
|
|
2436
|
-
```ts
|
|
2437
|
-
let base = new BigNumber(2);
|
|
2438
|
-
let exponent = new BigNumber(3);
|
|
2439
|
-
base.pow(exponent); // Returns BigNumber of value 8
|
|
2440
|
-
```
|
|
2441
|
-
|
|
2442
|
-
#### Method redAdd
|
|
2443
|
-
|
|
2444
|
-
Performs addition operation of the current BigNumber with the given number in a reduction context.
|
|
2445
|
-
Throws an error in case the number is not in a reduction context.
|
|
2446
|
-
|
|
2447
|
-
```ts
|
|
2448
|
-
redAdd(num: BigNumber): BigNumber
|
|
2449
|
-
```
|
|
2450
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2451
|
-
|
|
2452
|
-
Returns
|
|
2453
|
-
|
|
2454
|
-
Returns a new BigNumber that's the sum of the current BigNumber and the provided number in the reduction context.
|
|
2455
|
-
|
|
2456
|
-
Argument Details
|
|
2457
|
-
|
|
2458
|
-
+ **num**
|
|
2459
|
-
+ The number to add to the current BigNumber.
|
|
2460
|
-
|
|
2461
|
-
Example
|
|
2462
|
-
|
|
2463
|
-
```ts
|
|
2464
|
-
let bigNum = new BigNumber(10);
|
|
2465
|
-
let redCtx = new ReductionContext();
|
|
2466
|
-
bigNum.toRed(redCtx);
|
|
2467
|
-
bigNum.redAdd(new BigNumber(20)); // returns a BigNumber of 30 in reduction context
|
|
2468
|
-
```
|
|
2469
|
-
|
|
2470
|
-
#### Method redIAdd
|
|
2471
|
-
|
|
2472
|
-
Performs in-place addition operation of the current BigNumber with the given number in a reduction context.
|
|
2473
|
-
Throws an error in case the number is not in a reduction context.
|
|
2474
|
-
|
|
2475
|
-
```ts
|
|
2476
|
-
redIAdd(num: BigNumber): BigNumber
|
|
2477
|
-
```
|
|
2478
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2479
|
-
|
|
2480
|
-
Returns
|
|
2481
|
-
|
|
2482
|
-
Returns the modified current BigNumber after adding the provided number in the reduction context.
|
|
2483
|
-
|
|
2484
|
-
Argument Details
|
|
2485
|
-
|
|
2486
|
-
+ **num**
|
|
2487
|
-
+ The number to add to the current BigNumber.
|
|
2488
|
-
|
|
2489
|
-
Example
|
|
2490
|
-
|
|
2491
|
-
```ts
|
|
2492
|
-
let bigNum = new BigNumber(10);
|
|
2493
|
-
let redCtx = new ReductionContext();
|
|
2494
|
-
bigNum.toRed(redCtx);
|
|
2495
|
-
bigNum.redIAdd(new BigNumber(20)); // modifies the bigNum to 30 in reduction context
|
|
2496
|
-
```
|
|
2497
|
-
|
|
2498
|
-
#### Method redIMul
|
|
2499
|
-
|
|
2500
|
-
Performs an in-place multiplication of this BigNumber instance with another BigNumber within a reduction context.
|
|
2501
|
-
Expects that this BigNumber is within the reduction context i.e., it has been reduced.
|
|
2502
|
-
|
|
2503
|
-
```ts
|
|
2504
|
-
redIMul(num: BigNumber): BigNumber
|
|
2505
|
-
```
|
|
2506
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2507
|
-
|
|
2508
|
-
Returns
|
|
2509
|
-
|
|
2510
|
-
A BigNumber that is the result of the in-place multiplication operation, within the reduction context.
|
|
2511
|
-
|
|
2512
|
-
Argument Details
|
|
2513
|
-
|
|
2514
|
-
+ **num**
|
|
2515
|
-
+ The BigNumber to multiply with the current BigNumber.
|
|
2516
|
-
|
|
2517
|
-
Example
|
|
2518
|
-
|
|
2519
|
-
```ts
|
|
2520
|
-
let bigNum1 = new BigNumber('10').toRed(someRed);
|
|
2521
|
-
let bigNum2 = new BigNumber('5');
|
|
2522
|
-
bigNum1.redIMul(bigNum2);
|
|
2523
|
-
```
|
|
2524
|
-
|
|
2525
|
-
#### Method redISqr
|
|
2526
|
-
|
|
2527
|
-
In-place square of a "red" (reduced) BigNumber.
|
|
2528
|
-
This function squares the calling BigNumber and overwrites it with the result.
|
|
2529
|
-
It only works if the number is "reduced". A number is considered reduced
|
|
2530
|
-
if it has a `red` field that points to a reduction context object.
|
|
2531
|
-
|
|
2532
|
-
```ts
|
|
2533
|
-
redISqr(): BigNumber
|
|
2534
|
-
```
|
|
2535
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2536
|
-
|
|
2537
|
-
Returns
|
|
2538
|
-
|
|
2539
|
-
This BigNumber squared in place
|
|
2540
|
-
|
|
2541
|
-
Throws
|
|
2542
|
-
|
|
2543
|
-
If the BigNumber is not reduced
|
|
2544
|
-
|
|
2545
|
-
Example
|
|
2546
|
-
|
|
2547
|
-
```ts
|
|
2548
|
-
const num = new BigNumber('25').toRed(someRed);
|
|
2549
|
-
num.redISqr();
|
|
2550
|
-
console.log(num.toString()); // Outputs: '625' mod the red value
|
|
2551
|
-
```
|
|
2552
|
-
|
|
2553
|
-
#### Method redISub
|
|
2554
|
-
|
|
2555
|
-
Performs in-place subtraction operation of the current BigNumber with the given number in a reduction context.
|
|
2556
|
-
Throws an error in case the number is not in a reduction context.
|
|
2557
|
-
|
|
2558
|
-
```ts
|
|
2559
|
-
redISub(num: BigNumber): BigNumber
|
|
2560
|
-
```
|
|
2561
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2562
|
-
|
|
2563
|
-
Returns
|
|
2564
|
-
|
|
2565
|
-
Returns the modified current BigNumber after subtracting the provided number in the reduction context.
|
|
2566
|
-
|
|
2567
|
-
Argument Details
|
|
2568
|
-
|
|
2569
|
-
+ **num**
|
|
2570
|
-
+ The number to subtract from the current BigNumber.
|
|
2571
|
-
|
|
2572
|
-
Example
|
|
2573
|
-
|
|
2574
|
-
```ts
|
|
2575
|
-
let bigNum = new BigNumber(30);
|
|
2576
|
-
let redCtx = new ReductionContext();
|
|
2577
|
-
bigNum.toRed(redCtx);
|
|
2578
|
-
bigNum.redISub(new BigNumber(20)); // modifies the bigNum to 10 in reduction context
|
|
2579
|
-
```
|
|
2580
|
-
|
|
2581
|
-
#### Method redInvm
|
|
2582
|
-
|
|
2583
|
-
Find multiplicative inverse (reciprocal) in respect to reduction context.
|
|
2584
|
-
The method works only on numbers that have a reduction context set.
|
|
2585
|
-
|
|
2586
|
-
```ts
|
|
2587
|
-
redInvm(): BigNumber
|
|
2588
|
-
```
|
|
2589
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2590
|
-
|
|
2591
|
-
Returns
|
|
2592
|
-
|
|
2593
|
-
Returns a BigNumber that is multiplicative inverse in respect to the reduction context.
|
|
2594
|
-
|
|
2595
|
-
Throws
|
|
2596
|
-
|
|
2597
|
-
Will throw an error if this number does not have a reduction context.
|
|
2598
|
-
|
|
2599
|
-
Example
|
|
2600
|
-
|
|
2601
|
-
```ts
|
|
2602
|
-
let a = new BigNumber('2345', 16);
|
|
2603
|
-
a.red = someReductionContext;
|
|
2604
|
-
let aInverse = a.redInvm();
|
|
2605
|
-
```
|
|
2606
|
-
|
|
2607
|
-
#### Method redMul
|
|
2608
|
-
|
|
2609
|
-
Performs multiplication operation of the current BigNumber with the given number in a reduction context.
|
|
2610
|
-
Throws an error in case the number is not in a reduction context.
|
|
2611
|
-
|
|
2612
|
-
```ts
|
|
2613
|
-
redMul(num: BigNumber): BigNumber
|
|
2614
|
-
```
|
|
2615
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2616
|
-
|
|
2617
|
-
Returns
|
|
2618
|
-
|
|
2619
|
-
Returns a new BigNumber that's the product of the current BigNumber and the provided number in the reduction context.
|
|
2620
|
-
|
|
2621
|
-
Argument Details
|
|
2622
|
-
|
|
2623
|
-
+ **num**
|
|
2624
|
-
+ The number to multiply with the current BigNumber.
|
|
2625
|
-
|
|
2626
|
-
Example
|
|
2627
|
-
|
|
2628
|
-
```ts
|
|
2629
|
-
let bigNum = new BigNumber(10);
|
|
2630
|
-
let redCtx = new ReductionContext();
|
|
2631
|
-
bigNum.toRed(redCtx);
|
|
2632
|
-
bigNum.redMul(new BigNumber(20)); // returns a BigNumber of 200 in reduction context
|
|
2633
|
-
```
|
|
2634
|
-
|
|
2635
|
-
#### Method redNeg
|
|
2636
|
-
|
|
2637
|
-
Find negative version of this number in respect to reduction context.
|
|
2638
|
-
The method works only on numbers that have a reduction context set.
|
|
2639
|
-
|
|
2640
|
-
```ts
|
|
2641
|
-
redNeg(): BigNumber
|
|
2642
|
-
```
|
|
2643
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2644
|
-
|
|
2645
|
-
Returns
|
|
2646
|
-
|
|
2647
|
-
Returns a BigNumber that is the negative version of this number in respect to the reduction context.
|
|
2648
|
-
|
|
2649
|
-
Throws
|
|
2650
|
-
|
|
2651
|
-
Will throw an error if this number does not have a reduction context.
|
|
2652
|
-
|
|
2653
|
-
Example
|
|
2654
|
-
|
|
2655
|
-
```ts
|
|
2656
|
-
let a = new BigNumber('2345', 16);
|
|
2657
|
-
a.red = someReductionContext;
|
|
2658
|
-
let aNeg = a.redNeg();
|
|
2659
|
-
```
|
|
2660
|
-
|
|
2661
|
-
#### Method redPow
|
|
2662
|
-
|
|
2663
|
-
Raises this number to the power of 'num', in respect to reduction context.
|
|
2664
|
-
Note that 'num' must not have a reduction context set.
|
|
2665
|
-
|
|
2666
|
-
```ts
|
|
2667
|
-
redPow(num: BigNumber): BigNumber
|
|
2668
|
-
```
|
|
2669
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2670
|
-
|
|
2671
|
-
Returns
|
|
2672
|
-
|
|
2673
|
-
Returns a BigNumber that is this number raised to the power of 'num', in respect to the reduction context.
|
|
2674
|
-
|
|
2675
|
-
Argument Details
|
|
2676
|
-
|
|
2677
|
-
+ **num**
|
|
2678
|
-
+ The exponent to raise this number to.
|
|
2679
|
-
|
|
2680
|
-
Throws
|
|
2681
|
-
|
|
2682
|
-
Will throw an error if this number does not have a reduction context or 'num' has a reduction context.
|
|
2683
|
-
|
|
2684
|
-
Example
|
|
2685
|
-
|
|
2686
|
-
```ts
|
|
2687
|
-
let a = new BigNumber(3);
|
|
2688
|
-
a.red = someReductionContext;
|
|
2689
|
-
let b = new BigNumber(3);
|
|
2690
|
-
let result = a.redPow(b); // equivalent to (a^b) mod red
|
|
2691
|
-
```
|
|
2692
|
-
|
|
2693
|
-
#### Method redShl
|
|
2694
|
-
|
|
2695
|
-
Performs the shift left operation on the current BigNumber in the reduction context.
|
|
2696
|
-
Throws an error in case the number is not in a reduction context.
|
|
2697
|
-
|
|
2698
|
-
```ts
|
|
2699
|
-
redShl(num: number): BigNumber
|
|
2700
|
-
```
|
|
2701
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2702
|
-
|
|
2703
|
-
Returns
|
|
2704
|
-
|
|
2705
|
-
Returns a new BigNumber after performing the shift left operation on the current BigNumber in the reduction context.
|
|
2706
|
-
|
|
2707
|
-
Argument Details
|
|
2708
|
-
|
|
2709
|
-
+ **num**
|
|
2710
|
-
+ The positions to shift left the current BigNumber.
|
|
2711
|
-
|
|
2712
|
-
Example
|
|
2713
|
-
|
|
2714
|
-
```ts
|
|
2715
|
-
let bigNum = new BigNumber(1);
|
|
2716
|
-
let redCtx = new ReductionContext();
|
|
2717
|
-
bigNum.toRed(redCtx);
|
|
2718
|
-
bigNum.redShl(2); // returns a BigNumber of 4 in reduction context
|
|
2719
|
-
```
|
|
2720
|
-
|
|
2721
|
-
#### Method redSqr
|
|
2722
|
-
|
|
2723
|
-
Square of a "red" (reduced) BigNumber.
|
|
2724
|
-
This function squares the calling BigNumber and returns the result.
|
|
2725
|
-
It only works if the number is "reduced". A number is considered reduced
|
|
2726
|
-
if it has a `red` field that points to a reduction context object.
|
|
2727
|
-
|
|
2728
|
-
```ts
|
|
2729
|
-
redSqr(): BigNumber
|
|
2730
|
-
```
|
|
2731
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2732
|
-
|
|
2733
|
-
Returns
|
|
2734
|
-
|
|
2735
|
-
The square of the BigNumber
|
|
2736
|
-
|
|
2737
|
-
Throws
|
|
2738
|
-
|
|
2739
|
-
If the BigNumber is not reduced
|
|
2740
|
-
|
|
2741
|
-
Example
|
|
2742
|
-
|
|
2743
|
-
```ts
|
|
2744
|
-
const num = new BigNumber('25').toRed(someRed);
|
|
2745
|
-
const result = num.redSqr();
|
|
2746
|
-
console.log(result.toString()); // Outputs: '625' mod the red value
|
|
2747
|
-
```
|
|
2748
|
-
|
|
2749
|
-
#### Method redSqrt
|
|
2750
|
-
|
|
2751
|
-
Square root of a "red" (reduced) BigNumber.
|
|
2752
|
-
This function calculates the square root of the calling BigNumber
|
|
2753
|
-
and returns the result. It only works if the number is "reduced".
|
|
2754
|
-
A number is considered reduced if it has a `red`
|
|
2755
|
-
field that points to a reduction context object.
|
|
2756
|
-
|
|
2757
|
-
```ts
|
|
2758
|
-
redSqrt(): BigNumber
|
|
2759
|
-
```
|
|
2760
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2761
|
-
|
|
2762
|
-
Returns
|
|
2763
|
-
|
|
2764
|
-
The square root of the BigNumber
|
|
2765
|
-
|
|
2766
|
-
Throws
|
|
2767
|
-
|
|
2768
|
-
If the BigNumber is not reduced
|
|
2769
|
-
|
|
2770
|
-
Example
|
|
2771
|
-
|
|
2772
|
-
```ts
|
|
2773
|
-
const num = new BigNumber('4').toRed(someRed);
|
|
2774
|
-
const result = num.redSqrt();
|
|
2775
|
-
console.log(result.toString()); // Outputs: '2' mod the red value
|
|
2776
|
-
```
|
|
2777
|
-
|
|
2778
|
-
#### Method redSub
|
|
2779
|
-
|
|
2780
|
-
Performs subtraction operation of the current BigNumber with the given number in a reduction context.
|
|
2781
|
-
Throws an error in case the number is not in a reduction context.
|
|
2782
|
-
|
|
2783
|
-
```ts
|
|
2784
|
-
redSub(num: BigNumber): BigNumber
|
|
2785
|
-
```
|
|
2786
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2787
|
-
|
|
2788
|
-
Returns
|
|
2789
|
-
|
|
2790
|
-
Returns a new BigNumber that's the subtraction result of the current BigNumber and the provided number in the reduction context.
|
|
2791
|
-
|
|
2792
|
-
Argument Details
|
|
2793
|
-
|
|
2794
|
-
+ **num**
|
|
2795
|
-
+ The number to subtract from the current BigNumber.
|
|
2796
|
-
|
|
2797
|
-
Example
|
|
2798
|
-
|
|
2799
|
-
```ts
|
|
2800
|
-
let bigNum = new BigNumber(30);
|
|
2801
|
-
let redCtx = new ReductionContext();
|
|
2802
|
-
bigNum.toRed(redCtx);
|
|
2803
|
-
bigNum.redSub(new BigNumber(20)); // returns a BigNumber of 10 in reduction context
|
|
2804
|
-
```
|
|
2805
|
-
|
|
2806
|
-
#### Method setn
|
|
2807
|
-
|
|
2808
|
-
Set `bit` of `this` BigNumber. The `bit` is a position in the binary representation,
|
|
2809
|
-
and `val` is the value to be set at that position (`0` or `1`).
|
|
2810
|
-
|
|
2811
|
-
```ts
|
|
2812
|
-
setn(bit: number, val: 0 | 1 | true | false): this
|
|
2813
|
-
```
|
|
2814
|
-
|
|
2815
|
-
Returns
|
|
2816
|
-
|
|
2817
|
-
Returns the BigNumber after setting the value at the bit position.
|
|
2818
|
-
|
|
2819
|
-
Argument Details
|
|
2820
|
-
|
|
2821
|
-
+ **bit**
|
|
2822
|
-
+ The bit position to set.
|
|
2823
|
-
+ **val**
|
|
2824
|
-
+ The value to set at the bit position.
|
|
2825
|
-
|
|
2826
|
-
Example
|
|
2827
|
-
|
|
2828
|
-
```ts
|
|
2829
|
-
const num = new BigNumber('42');
|
|
2830
|
-
num.setn(2, 1);
|
|
2831
|
-
console.log(num.toString());
|
|
2832
|
-
```
|
|
2833
|
-
|
|
2834
|
-
#### Method shln
|
|
2835
|
-
|
|
2836
|
-
Performs a bitwise left shift operation on a clone of the BigNumber instance.
|
|
2837
|
-
|
|
2838
|
-
```ts
|
|
2839
|
-
shln(bits): BigNumber
|
|
2840
|
-
```
|
|
2841
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2842
|
-
|
|
2843
|
-
Returns
|
|
2844
|
-
|
|
2845
|
-
A new BigNumber, which is the result of the shift operation.
|
|
2846
|
-
|
|
2847
|
-
Argument Details
|
|
2848
|
-
|
|
2849
|
-
+ **bits**
|
|
2850
|
-
+ The number of positions to shift.
|
|
2851
|
-
|
|
2852
|
-
Example
|
|
2853
|
-
|
|
2854
|
-
```ts
|
|
2855
|
-
let myNumber = new BigNumber(4);
|
|
2856
|
-
let shiftedNumber = myNumber.shln(2);
|
|
2857
|
-
console.log(shiftedNumber.toString()); // Outputs "16"
|
|
2858
|
-
```
|
|
2859
|
-
|
|
2860
|
-
#### Method shrn
|
|
2861
|
-
|
|
2862
|
-
Performs a bitwise right shift operation on a clone of the BigNumber instance.
|
|
2863
|
-
|
|
2864
|
-
```ts
|
|
2865
|
-
shrn(bits): BigNumber
|
|
2866
|
-
```
|
|
2867
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2868
|
-
|
|
2869
|
-
Returns
|
|
2870
|
-
|
|
2871
|
-
A new BigNumber resulting from the shift operation.
|
|
2872
|
-
|
|
2873
|
-
Argument Details
|
|
2874
|
-
|
|
2875
|
-
+ **bits**
|
|
2876
|
-
+ The number of bits to shift.
|
|
2877
|
-
|
|
2878
|
-
Example
|
|
2879
|
-
|
|
2880
|
-
```ts
|
|
2881
|
-
let myNumber = new BigNumber(16);
|
|
2882
|
-
let shiftedNumber = myNumber.shrn(3);
|
|
2883
|
-
console.log(shiftedNumber.toString()); // Outputs "2"
|
|
2884
|
-
```
|
|
2885
|
-
|
|
2886
|
-
#### Method sqr
|
|
2887
|
-
|
|
2888
|
-
Squares the BigNumber instance.
|
|
2889
|
-
|
|
2890
|
-
```ts
|
|
2891
|
-
sqr(): BigNumber
|
|
2892
|
-
```
|
|
2893
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2894
|
-
|
|
2895
|
-
Returns
|
|
2896
|
-
|
|
2897
|
-
The BigNumber squared.
|
|
2898
|
-
|
|
2899
|
-
Example
|
|
2900
|
-
|
|
2901
|
-
```ts
|
|
2902
|
-
const bn = new BigNumber('12345');
|
|
2903
|
-
const result = bn.sqr();
|
|
2904
|
-
```
|
|
2905
|
-
|
|
2906
|
-
#### Method strip
|
|
2907
|
-
|
|
2908
|
-
Removes leading zeros.
|
|
2909
|
-
|
|
2910
|
-
```ts
|
|
2911
|
-
strip(): this
|
|
2912
|
-
```
|
|
2913
|
-
|
|
2914
|
-
Returns
|
|
2915
|
-
|
|
2916
|
-
- Returns the BigNumber after stripping leading zeros.
|
|
2917
|
-
|
|
2918
|
-
Example
|
|
2919
|
-
|
|
2920
|
-
```ts
|
|
2921
|
-
const bn = new BigNumber("000000", 2, "be");
|
|
2922
|
-
bn.strip();
|
|
2923
|
-
// bn now represents 0
|
|
2924
|
-
```
|
|
2925
|
-
|
|
2926
|
-
#### Method sub
|
|
2927
|
-
|
|
2928
|
-
Subtract `num` from `this` BigNumber.
|
|
2929
|
-
|
|
2930
|
-
```ts
|
|
2931
|
-
sub(num: BigNumber): BigNumber
|
|
2932
|
-
```
|
|
2933
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2934
|
-
|
|
2935
|
-
Returns
|
|
2936
|
-
|
|
2937
|
-
Returns a new BigNumber which is the result of the subtraction.
|
|
2938
|
-
|
|
2939
|
-
Argument Details
|
|
2940
|
-
|
|
2941
|
-
+ **num**
|
|
2942
|
-
+ The BigNumber to be subtracted from `this` BigNumber.
|
|
2943
|
-
|
|
2944
|
-
Example
|
|
2945
|
-
|
|
2946
|
-
```ts
|
|
2947
|
-
const num1 = new BigNumber('20');
|
|
2948
|
-
const subResult = num1.sub(new BigNumber('10'));
|
|
2949
|
-
console.log(subResult.toString());
|
|
2950
|
-
```
|
|
2951
|
-
|
|
2952
|
-
#### Method subn
|
|
2953
|
-
|
|
2954
|
-
Returns a new BigNumber that is the result of subtracting a plain number from the original BigNumber.
|
|
2955
|
-
|
|
2956
|
-
```ts
|
|
2957
|
-
subn(num: number): BigNumber
|
|
2958
|
-
```
|
|
2959
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
2960
|
-
|
|
2961
|
-
Returns
|
|
2962
|
-
|
|
2963
|
-
Returns a new BigNumber which is the difference of the original BigNumber and the plain number.
|
|
2964
|
-
|
|
2965
|
-
Argument Details
|
|
2966
|
-
|
|
2967
|
-
+ **num**
|
|
2968
|
-
+ The plain number to subtract.
|
|
2969
|
-
|
|
2970
|
-
Example
|
|
2971
|
-
|
|
2972
|
-
```ts
|
|
2973
|
-
const myNumber = new BigNumber(52);
|
|
2974
|
-
const newNumber = myNumber.subn(2); // newNumber becomes 50, myNumber doesn't change.
|
|
2975
|
-
```
|
|
2976
|
-
|
|
2977
|
-
#### Method testn
|
|
2978
|
-
|
|
2979
|
-
Tests if the nth bit of the BigNumber is set.
|
|
2980
|
-
|
|
2981
|
-
```ts
|
|
2982
|
-
testn(bit: number): boolean
|
|
2983
|
-
```
|
|
2984
|
-
|
|
2985
|
-
Returns
|
|
2986
|
-
|
|
2987
|
-
A boolean indicating whether the nth bit is set.
|
|
2988
|
-
|
|
2989
|
-
Argument Details
|
|
2990
|
-
|
|
2991
|
-
+ **bit**
|
|
2992
|
-
+ The position of the bit to test.
|
|
2993
|
-
|
|
2994
|
-
Example
|
|
2995
|
-
|
|
2996
|
-
```ts
|
|
2997
|
-
let myNumber = new BigNumber(10); // 1010 in binary
|
|
2998
|
-
myNumber.testn(1); // Returns true (indicating that the second bit from right is set)
|
|
2999
|
-
```
|
|
3000
|
-
|
|
3001
|
-
#### Method toArray
|
|
3002
|
-
|
|
3003
|
-
Converts the BigNumber instance to a JavaScript number array.
|
|
3004
|
-
|
|
3005
|
-
```ts
|
|
3006
|
-
toArray(endian: "le" | "be" = "be", length?: number): number[]
|
|
3007
|
-
```
|
|
3008
|
-
|
|
3009
|
-
Returns
|
|
3010
|
-
|
|
3011
|
-
The JavaScript array representation of the BigNumber instance.
|
|
3012
|
-
|
|
3013
|
-
Argument Details
|
|
3014
|
-
|
|
3015
|
-
+ **endian**
|
|
3016
|
-
+ The endian for converting BigNumber to array. Default value is 'be'.
|
|
3017
|
-
+ **length**
|
|
3018
|
-
+ The length for the resultant array. Default value is undefined.
|
|
3019
|
-
|
|
3020
|
-
Example
|
|
3021
|
-
|
|
3022
|
-
```ts
|
|
3023
|
-
const bn = new BigNumber('123456', 10, 'be');
|
|
3024
|
-
bn.toArray('be', 8);
|
|
3025
|
-
```
|
|
3026
|
-
|
|
3027
|
-
#### Method toBitArray
|
|
3028
|
-
|
|
3029
|
-
Convert a big number to a boolean array representing
|
|
3030
|
-
a binary number, where each array index is a bit.
|
|
3031
|
-
|
|
3032
|
-
```ts
|
|
3033
|
-
static toBitArray(num: BigNumber): Array<0 | 1>
|
|
3034
|
-
```
|
|
3035
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
3036
|
-
|
|
3037
|
-
Returns
|
|
3038
|
-
|
|
3039
|
-
Returns an array of booleans representing
|
|
3040
|
-
a binary number, with each array index being a bit.
|
|
3041
|
-
|
|
3042
|
-
Argument Details
|
|
3043
|
-
|
|
3044
|
-
+ **num**
|
|
3045
|
-
+ The big number to convert.
|
|
3046
|
-
|
|
3047
|
-
Example
|
|
3048
|
-
|
|
3049
|
-
```ts
|
|
3050
|
-
const BigNumber = require("./BigNumber");
|
|
3051
|
-
const bn = new BigNumber('6'); // binary: 110
|
|
3052
|
-
const bits = BigNumber.toBitArray(bn); // [1,1,0]
|
|
3053
|
-
```
|
|
3054
|
-
|
|
3055
|
-
#### Method toBitArray
|
|
3056
|
-
|
|
3057
|
-
Convert this big number to a boolean array representing
|
|
3058
|
-
a binary number, where each array index is a bit.
|
|
3059
|
-
|
|
3060
|
-
```ts
|
|
3061
|
-
toBitArray(): Array<0 | 1>
|
|
3062
|
-
```
|
|
3063
|
-
|
|
3064
|
-
Returns
|
|
3065
|
-
|
|
3066
|
-
Returns an array of booleans representing a binary number.
|
|
3067
|
-
|
|
3068
|
-
Example
|
|
3069
|
-
|
|
3070
|
-
```ts
|
|
3071
|
-
const BigNumber = require("./BigNumber");
|
|
3072
|
-
const bn = new BigNumber('6'); // binary: 110
|
|
3073
|
-
const bits = bn.toBitArray(); // [ 1, 1, 0 ]
|
|
3074
|
-
```
|
|
3075
|
-
|
|
3076
|
-
#### Method toBits
|
|
3077
|
-
|
|
3078
|
-
Converts this BigNumber to a number representing the "bits" value in a block header.
|
|
3079
|
-
|
|
3080
|
-
```ts
|
|
3081
|
-
toBits(): number
|
|
3082
|
-
```
|
|
3083
|
-
|
|
3084
|
-
Returns
|
|
3085
|
-
|
|
3086
|
-
Returns a number equivalent to the "bits" value in a block header.
|
|
3087
|
-
|
|
3088
|
-
Example
|
|
3089
|
-
|
|
3090
|
-
```ts
|
|
3091
|
-
const bigNumber = new BigNumber(1);
|
|
3092
|
-
const bits = bigNumber.toBits();
|
|
3093
|
-
```
|
|
3094
|
-
|
|
3095
|
-
#### Method toHex
|
|
3096
|
-
|
|
3097
|
-
Converts this BigNumber to a hexadecimal string.
|
|
3098
|
-
|
|
3099
|
-
```ts
|
|
3100
|
-
toHex(length: number = 0): string
|
|
3101
|
-
```
|
|
3102
|
-
|
|
3103
|
-
Returns
|
|
3104
|
-
|
|
3105
|
-
Returns a string representing the hexadecimal value of this BigNumber.
|
|
3106
|
-
|
|
3107
|
-
Argument Details
|
|
3108
|
-
|
|
3109
|
-
+ **length**
|
|
3110
|
-
+ The minimum length of the hex string
|
|
3111
|
-
|
|
3112
|
-
Example
|
|
3113
|
-
|
|
3114
|
-
```ts
|
|
3115
|
-
const bigNumber = new BigNumber(255);
|
|
3116
|
-
const hex = bigNumber.toHex();
|
|
3117
|
-
```
|
|
3118
|
-
|
|
3119
|
-
#### Method toJSON
|
|
3120
|
-
|
|
3121
|
-
Converts the BigNumber instance to a JSON-formatted string.
|
|
3122
|
-
|
|
3123
|
-
```ts
|
|
3124
|
-
toJSON(): string
|
|
3125
|
-
```
|
|
3126
|
-
|
|
3127
|
-
Returns
|
|
3128
|
-
|
|
3129
|
-
The JSON string representation of the BigNumber instance.
|
|
3130
|
-
|
|
3131
|
-
Example
|
|
3132
|
-
|
|
3133
|
-
```ts
|
|
3134
|
-
const bn = new BigNumber('123456', 10, 'be');
|
|
3135
|
-
bn.toJSON();
|
|
3136
|
-
```
|
|
3137
|
-
|
|
3138
|
-
#### Method toNumber
|
|
3139
|
-
|
|
3140
|
-
Converts the BigNumber instance to a JavaScript number.
|
|
3141
|
-
Please note that JavaScript numbers are only precise up to 53 bits.
|
|
3142
|
-
|
|
3143
|
-
```ts
|
|
3144
|
-
toNumber(): number
|
|
3145
|
-
```
|
|
3146
|
-
|
|
3147
|
-
Returns
|
|
3148
|
-
|
|
3149
|
-
The JavaScript number representation of the BigNumber instance.
|
|
3150
|
-
|
|
3151
|
-
Throws
|
|
3152
|
-
|
|
3153
|
-
If the BigNumber instance cannot be safely stored in a JavaScript number
|
|
3154
|
-
|
|
3155
|
-
Example
|
|
3156
|
-
|
|
3157
|
-
```ts
|
|
3158
|
-
const bn = new BigNumber('123456', 10, 'be');
|
|
3159
|
-
bn.toNumber();
|
|
3160
|
-
```
|
|
3161
|
-
|
|
3162
|
-
#### Method toRed
|
|
3163
|
-
|
|
3164
|
-
Converts a BigNumber to a reduction context ensuring the number is a positive integer and is not already in a reduction context.
|
|
3165
|
-
Throws an error in case the number is either negative or already in a reduction context.
|
|
3166
|
-
|
|
3167
|
-
```ts
|
|
3168
|
-
toRed(ctx: ReductionContext): BigNumber
|
|
3169
|
-
```
|
|
3170
|
-
See also: [BigNumber](./primitives.md#class-bignumber), [ReductionContext](./primitives.md#class-reductioncontext)
|
|
3171
|
-
|
|
3172
|
-
Returns
|
|
3173
|
-
|
|
3174
|
-
Returns the BigNumber in the given ReductionContext.
|
|
3175
|
-
|
|
3176
|
-
Argument Details
|
|
3177
|
-
|
|
3178
|
-
+ **ctx**
|
|
3179
|
-
+ The ReductionContext to convert the BigNumber to.
|
|
3180
|
-
|
|
3181
|
-
Example
|
|
3182
|
-
|
|
3183
|
-
```ts
|
|
3184
|
-
let bigNum = new BigNumber(10);
|
|
3185
|
-
let redCtx = new ReductionContext();
|
|
3186
|
-
bigNum.toRed(redCtx);
|
|
3187
|
-
```
|
|
3188
|
-
|
|
3189
|
-
#### Method toScriptNum
|
|
3190
|
-
|
|
3191
|
-
Converts this BigNumber to a number in the format used in Bitcoin scripts.
|
|
3192
|
-
|
|
3193
|
-
```ts
|
|
3194
|
-
toScriptNum(): number[]
|
|
3195
|
-
```
|
|
3196
|
-
|
|
3197
|
-
Returns
|
|
3198
|
-
|
|
3199
|
-
Returns the equivalent to this BigNumber as a Bitcoin script number.
|
|
3200
|
-
|
|
3201
|
-
Example
|
|
3202
|
-
|
|
3203
|
-
```ts
|
|
3204
|
-
const bigNumber = new BigNumber(258)
|
|
3205
|
-
const num = bigNumber.toScriptNum() // equivalent to bigNumber.toSm('little')
|
|
3206
|
-
```
|
|
677
|
+
Returns the equivalent to this BigNumber as a Bitcoin script number.
|
|
3207
678
|
|
|
3208
679
|
#### Method toSm
|
|
3209
680
|
|
|
@@ -3222,13 +693,6 @@ Argument Details
|
|
|
3222
693
|
+ **endian**
|
|
3223
694
|
+ Defines endianess. If not provided, big endian is assumed.
|
|
3224
695
|
|
|
3225
|
-
Example
|
|
3226
|
-
|
|
3227
|
-
```ts
|
|
3228
|
-
const bigNumber = new BigNumber(-1);
|
|
3229
|
-
const num = bigNumber.toSm('little'); // [0x81]
|
|
3230
|
-
```
|
|
3231
|
-
|
|
3232
696
|
#### Method toString
|
|
3233
697
|
|
|
3234
698
|
function toString() { [native code] }
|
|
@@ -3250,256 +714,6 @@ Argument Details
|
|
|
3250
714
|
+ **padding**
|
|
3251
715
|
+ Represents the minimum number of digits to represent the BigNumber as a string. Default is 1.
|
|
3252
716
|
|
|
3253
|
-
Throws
|
|
3254
|
-
|
|
3255
|
-
If base is not between 2 and 36.
|
|
3256
|
-
|
|
3257
|
-
Example
|
|
3258
|
-
|
|
3259
|
-
```ts
|
|
3260
|
-
const bn = new BigNumber('123456', 10, 'be');
|
|
3261
|
-
bn.toString(16); // Converts the BigNumber to a hexadecimal string.
|
|
3262
|
-
```
|
|
3263
|
-
|
|
3264
|
-
#### Method toTwos
|
|
3265
|
-
|
|
3266
|
-
Converts this big number to two's complement with a specified bit width.
|
|
3267
|
-
|
|
3268
|
-
```ts
|
|
3269
|
-
toTwos(width: number): BigNumber
|
|
3270
|
-
```
|
|
3271
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
3272
|
-
|
|
3273
|
-
Returns
|
|
3274
|
-
|
|
3275
|
-
Returns the two's complement of the big number.
|
|
3276
|
-
|
|
3277
|
-
Argument Details
|
|
3278
|
-
|
|
3279
|
-
+ **width**
|
|
3280
|
-
+ The bit width.
|
|
3281
|
-
|
|
3282
|
-
Example
|
|
3283
|
-
|
|
3284
|
-
```ts
|
|
3285
|
-
const BigNumber = require("./BigNumber");
|
|
3286
|
-
const bn = new BigNumber('-1234');
|
|
3287
|
-
const twosComp = bn.toTwos(16);
|
|
3288
|
-
```
|
|
3289
|
-
|
|
3290
|
-
#### Method uand
|
|
3291
|
-
|
|
3292
|
-
Performs a bitwise AND operation without considering signed bit
|
|
3293
|
-
(no negative values) which returns a new BigNumber, similar to the `and` method.
|
|
3294
|
-
|
|
3295
|
-
```ts
|
|
3296
|
-
uand(num: BigNumber): BigNumber
|
|
3297
|
-
```
|
|
3298
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
3299
|
-
|
|
3300
|
-
Returns
|
|
3301
|
-
|
|
3302
|
-
Returns new BigNumber resulting from the bitwise AND operation without sign consideration.
|
|
3303
|
-
|
|
3304
|
-
Argument Details
|
|
3305
|
-
|
|
3306
|
-
+ **num**
|
|
3307
|
-
+ The BigNumber to perform the bitwise AND operation with.
|
|
3308
|
-
|
|
3309
|
-
Example
|
|
3310
|
-
|
|
3311
|
-
```ts
|
|
3312
|
-
const num1 = new BigNumber('10');
|
|
3313
|
-
const num2 = new BigNumber('20');
|
|
3314
|
-
console.log(num1.uand(num2).toString());
|
|
3315
|
-
```
|
|
3316
|
-
|
|
3317
|
-
#### Method ucmp
|
|
3318
|
-
|
|
3319
|
-
Performs an unsigned comparison between this BigNumber instance and another.
|
|
3320
|
-
|
|
3321
|
-
```ts
|
|
3322
|
-
ucmp(num: BigNumber): 1 | 0 | -1
|
|
3323
|
-
```
|
|
3324
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
3325
|
-
|
|
3326
|
-
Returns
|
|
3327
|
-
|
|
3328
|
-
Returns 1 if this BigNumber is bigger, -1 if it is smaller, and 0 if they are equal.
|
|
3329
|
-
|
|
3330
|
-
Argument Details
|
|
3331
|
-
|
|
3332
|
-
+ **num**
|
|
3333
|
-
+ The BigNumber instance to compare with.
|
|
3334
|
-
|
|
3335
|
-
Example
|
|
3336
|
-
|
|
3337
|
-
```ts
|
|
3338
|
-
let bigNumber1 = new BigNumber('1234');
|
|
3339
|
-
let bigNumber2 = new BigNumber('2345');
|
|
3340
|
-
let comparisonResult = bigNumber1.ucmp(bigNumber2); // Returns -1
|
|
3341
|
-
```
|
|
3342
|
-
|
|
3343
|
-
#### Method umod
|
|
3344
|
-
|
|
3345
|
-
Returns the remainder after unsigned division of one `BigNumber` by another `BigNumber`.
|
|
3346
|
-
|
|
3347
|
-
```ts
|
|
3348
|
-
umod(num: BigNumber): BigNumber
|
|
3349
|
-
```
|
|
3350
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
3351
|
-
|
|
3352
|
-
Returns
|
|
3353
|
-
|
|
3354
|
-
The remainder `BigNumber` after unsigned division.
|
|
3355
|
-
Note: Here 'unsigned division' means that signs of the numbers are ignored.
|
|
3356
|
-
|
|
3357
|
-
Argument Details
|
|
3358
|
-
|
|
3359
|
-
+ **num**
|
|
3360
|
-
+ The divisor `BigNumber`.
|
|
3361
|
-
|
|
3362
|
-
Example
|
|
3363
|
-
|
|
3364
|
-
```ts
|
|
3365
|
-
const bigNum1 = new BigNumber('-100');
|
|
3366
|
-
const bigNum2 = new BigNumber('45');
|
|
3367
|
-
const remainder = bigNum1.umod(bigNum2); // remainder here would be '10' as signs are ignored.
|
|
3368
|
-
```
|
|
3369
|
-
|
|
3370
|
-
#### Method uor
|
|
3371
|
-
|
|
3372
|
-
Performs a bitwise OR operation on the current instance and given
|
|
3373
|
-
BigNumber without considering signed bit(no negative values) and returns a new BigNumber,
|
|
3374
|
-
similar to the `or` method.
|
|
3375
|
-
|
|
3376
|
-
```ts
|
|
3377
|
-
uor(num: BigNumber): BigNumber
|
|
3378
|
-
```
|
|
3379
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
3380
|
-
|
|
3381
|
-
Returns
|
|
3382
|
-
|
|
3383
|
-
Returns a new BigNumber resulting from the bitwise OR operation without sign consideration.
|
|
3384
|
-
|
|
3385
|
-
Argument Details
|
|
3386
|
-
|
|
3387
|
-
+ **num**
|
|
3388
|
-
+ The BigNumber to perform the bitwise OR operation with.
|
|
3389
|
-
|
|
3390
|
-
Example
|
|
3391
|
-
|
|
3392
|
-
```ts
|
|
3393
|
-
const num1 = new BigNumber('10');
|
|
3394
|
-
const num2 = new BigNumber('20');
|
|
3395
|
-
console.log(num1.uor(num2).toString());
|
|
3396
|
-
```
|
|
3397
|
-
|
|
3398
|
-
#### Method ushln
|
|
3399
|
-
|
|
3400
|
-
Performs an unsigned bitwise shift left operation on a clone of the BigNumber instance.
|
|
3401
|
-
|
|
3402
|
-
```ts
|
|
3403
|
-
ushln(bits): BigNumber
|
|
3404
|
-
```
|
|
3405
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
3406
|
-
|
|
3407
|
-
Returns
|
|
3408
|
-
|
|
3409
|
-
A new BigNumber resulting from the shift operation.
|
|
3410
|
-
|
|
3411
|
-
Argument Details
|
|
3412
|
-
|
|
3413
|
-
+ **bits**
|
|
3414
|
-
+ The number of bits to shift.
|
|
3415
|
-
|
|
3416
|
-
Example
|
|
3417
|
-
|
|
3418
|
-
```ts
|
|
3419
|
-
let myNumber = new BigNumber(4);
|
|
3420
|
-
let shiftedNumber = myNumber.ushln(2);
|
|
3421
|
-
console.log(shiftedNumber.toString()); // Outputs "16"
|
|
3422
|
-
```
|
|
3423
|
-
|
|
3424
|
-
#### Method ushrn
|
|
3425
|
-
|
|
3426
|
-
Performs an unsigned bitwise shift right operation on a clone of the BigNumber instance.
|
|
3427
|
-
|
|
3428
|
-
```ts
|
|
3429
|
-
ushrn(bits): BigNumber
|
|
3430
|
-
```
|
|
3431
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
3432
|
-
|
|
3433
|
-
Returns
|
|
3434
|
-
|
|
3435
|
-
A new BigNumber resulting from the shift operation.
|
|
3436
|
-
|
|
3437
|
-
Argument Details
|
|
3438
|
-
|
|
3439
|
-
+ **bits**
|
|
3440
|
-
+ The number of bits to shift.
|
|
3441
|
-
|
|
3442
|
-
Example
|
|
3443
|
-
|
|
3444
|
-
```ts
|
|
3445
|
-
let myNumber = new BigNumber(20);
|
|
3446
|
-
let shiftedNumber = myNumber.ushrn(2);
|
|
3447
|
-
console.log(shiftedNumber.toString()); // Outputs "5"
|
|
3448
|
-
```
|
|
3449
|
-
|
|
3450
|
-
#### Method uxor
|
|
3451
|
-
|
|
3452
|
-
Performs an unsigned XOR operation on this BigNumber with the supplied BigNumber. Returns a new BigNumber.
|
|
3453
|
-
|
|
3454
|
-
```ts
|
|
3455
|
-
uxor(num: BigNumber): BigNumber
|
|
3456
|
-
```
|
|
3457
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
3458
|
-
|
|
3459
|
-
Returns
|
|
3460
|
-
|
|
3461
|
-
Returns a new BigNumber resulting from the unsigned bitwise XOR operation.
|
|
3462
|
-
|
|
3463
|
-
Argument Details
|
|
3464
|
-
|
|
3465
|
-
+ **num**
|
|
3466
|
-
+ The BigNumber with which the unsigned bitwise XOR operation is to be performed.
|
|
3467
|
-
|
|
3468
|
-
Example
|
|
3469
|
-
|
|
3470
|
-
```ts
|
|
3471
|
-
const num1 = new BigNumber('30');
|
|
3472
|
-
const num2 = new BigNumber('40');
|
|
3473
|
-
console.log(num1.uxor(num2).toString()); // Output will be the result of unsigned XOR operation
|
|
3474
|
-
```
|
|
3475
|
-
|
|
3476
|
-
#### Method xor
|
|
3477
|
-
|
|
3478
|
-
Performs a bitwise XOR operation which returns a new BigNumber, and keeps the bits
|
|
3479
|
-
set in the result only if the corresponding bits in the operands are different.
|
|
3480
|
-
|
|
3481
|
-
```ts
|
|
3482
|
-
xor(num: BigNumber): BigNumber
|
|
3483
|
-
```
|
|
3484
|
-
See also: [BigNumber](./primitives.md#class-bignumber)
|
|
3485
|
-
|
|
3486
|
-
Returns
|
|
3487
|
-
|
|
3488
|
-
Returns a new BigNumber resulting from the bitwise XOR operation.
|
|
3489
|
-
|
|
3490
|
-
Argument Details
|
|
3491
|
-
|
|
3492
|
-
+ **num**
|
|
3493
|
-
+ The BigNumber to perform the bitwise XOR operation with.
|
|
3494
|
-
|
|
3495
|
-
Example
|
|
3496
|
-
|
|
3497
|
-
```ts
|
|
3498
|
-
const num1 = new BigNumber('10');
|
|
3499
|
-
const num2 = new BigNumber('20');
|
|
3500
|
-
console.log(num1.xor(num2).toString());
|
|
3501
|
-
```
|
|
3502
|
-
|
|
3503
717
|
#### Method zeroBits
|
|
3504
718
|
|
|
3505
719
|
Returns the number of trailing zero bits in the big number.
|
|
@@ -3516,7 +730,6 @@ in the binary representation of the big number.
|
|
|
3516
730
|
Example
|
|
3517
731
|
|
|
3518
732
|
```ts
|
|
3519
|
-
const BigNumber = require("./BigNumber");
|
|
3520
733
|
const bn = new BigNumber('8'); // binary: 1000
|
|
3521
734
|
const zeroBits = bn.zeroBits(); // 3
|
|
3522
735
|
```
|
|
@@ -4276,9 +1489,9 @@ See also: [BigNumber](./primitives.md#class-bignumber)
|
|
|
4276
1489
|
Argument Details
|
|
4277
1490
|
|
|
4278
1491
|
+ **input**
|
|
4279
|
-
+ The BigNumber to be shifted.
|
|
1492
|
+
+ The BigNumber to be shifted (will contain HI part).
|
|
4280
1493
|
+ **out**
|
|
4281
|
-
+ The BigNumber to hold the shifted result.
|
|
1494
|
+
+ The BigNumber to hold the shifted result (LO part).
|
|
4282
1495
|
|
|
4283
1496
|
Example
|
|
4284
1497
|
|