-
Notifications
You must be signed in to change notification settings - Fork 30.2k
/
index.d.ts
353 lines (341 loc) · 15.5 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
declare namespace Big {
type BigSource = number | string | Big;
/**
* GT = 1, EQ = 0, LT = -1
*/
type Comparison = -1 | 0 | 1;
/**
* RoundDown = 0, RoundHalfUp = 1, RoundHalfEven = 2, RoundUp = 3
*/
type RoundingMode = 0 | 1 | 2 | 3;
interface BigConstructor {
/**
* Returns a new instance of a Big number object
*
* String values may be in exponential, as well as normal (non-exponential) notation.
* There is no limit to the number of digits of a string value (other than that of Javascript's maximum array size), but the largest recommended exponent magnitude is 1e 6.
* Infinity, NaN and hexadecimal literal strings, e.g. '0xff', are not valid.
* String values in octal literal form will be interpreted as decimals, e.g. '011' is 11, not 9.
*
* @throws `NaN` on an invalid value.
*/
new(value: BigSource): Big;
/**
* Returns a new instance of a Big number object
*
* String values may be in exponential, as well as normal (non-exponential) notation.
* There is no limit to the number of digits of a string value (other than that of Javascript's maximum array size), but the largest recommended exponent magnitude is 1e 6.
* Infinity, NaN and hexadecimal literal strings, e.g. '0xff', are not valid.
* String values in octal literal form will be interpreted as decimals, e.g. '011' is 11, not 9.
*
* @throws `NaN` on an invalid value.
*/
(value: BigSource): Big;
/**
* Create an additional Big number constructor
*
* Values created with the returned constructor will have a separate set of configuration values.
* This can be used to create Big objects with different DP and RM values.
* Big numbers created by different constructors can be used together in operations, and it is the DP and RM setting of the Big number that an operation is called upon that will apply.
* In the interest of memory efficiency, all Big number constructors share the same prototype object,
* so while the DP and RM (and any other own properties) of a constructor are isolated and untouchable by another, its prototype methods are not.
*/
(): BigConstructor;
/**
* The maximum number of decimal places of the results of operations involving division.
* It is relevant only to the div and sqrt methods, and the pow method when the exponent is negative.
*
* 0 to 1e 6 inclusive
* Default value: 20
*/
DP: number;
/**
* The rounding mode used in the above operations and by round, toExponential, toFixed and toPrecision.
* Default value: 1
*/
RM: number;
/**
* The negative exponent value at and below which toString returns exponential notation.
*
* -1e 6 to 0 inclusive
* Default value: -7
*/
NE: number;
/**
* The positive exponent value at and above which toString returns exponential notation.
*
* 0 to 1e 6 inclusive
* Default value: 21
*/
PE: number;
/**
* When set to true, an error will be thrown if a primitive number is passed to the Big constructor,
* or if valueOf is called, or if toNumber is called on a Big which cannot be converted to a primitive number without a loss of precision.
*
* true|false
* Default value: false
*/
strict: boolean;
/** Readonly rounding modes */
/**
* Rounds towards zero.
* I.e. truncate, no rounding.
*/
readonly roundDown: 0;
/**
* Rounds towards nearest neighbour.
* If equidistant, rounds away from zero.
*/
readonly roundHalfUp: 1;
/**
* Rounds towards nearest neighbour.
* If equidistant, rounds towards even neighbour.
*/
readonly roundHalfEven: 2;
/**
* Rounds away from zero.
*/
readonly roundUp: 3;
readonly Big: BigConstructor;
}
interface Big {
/** Returns a Big number whose value is the absolute value, i.e. the magnitude, of this Big number. */
abs(): Big;
/**
* Returns a Big number whose value is the value of this Big number plus n - alias for .plus().
*
* @throws `NaN` if n is invalid.
*/
add(n: BigSource): Big;
/**
* Compare the values.
*
* @throws `NaN` if n is invalid.
*/
cmp(n: BigSource): Comparison;
/**
* Returns a Big number whose value is the value of this Big number divided by n.
*
* If the result has more fraction digits than is specified by Big.DP, it will be rounded to Big.DP decimal places using rounding mode Big.RM.
*
* @throws `NaN` if n is invalid.
* @throws `±Infinity` on division by zero.
* @throws `NaN` on division of zero by zero.
*/
div(n: BigSource): Big;
/**
* Returns true if the value of this Big equals the value of n, otherwise returns false.
*
* @throws `NaN` if n is invalid.
*/
eq(n: BigSource): boolean;
/**
* Returns true if the value of this Big is greater than the value of n, otherwise returns false.
*
* @throws `NaN` if n is invalid.
*/
gt(n: BigSource): boolean;
/**
* Returns true if the value of this Big is greater than or equal to the value of n, otherwise returns false.
*
* @throws `NaN` if n is invalid.
*/
gte(n: BigSource): boolean;
/**
* Returns true if the value of this Big is less than the value of n, otherwise returns false.
*
* @throws `NaN` if n is invalid.
*/
lt(n: BigSource): boolean;
/**
* Returns true if the value of this Big is less than or equal to the value of n, otherwise returns false.
*
* @throws `NaN` if n is invalid.
*/
lte(n: BigSource): boolean;
/**
* Returns a Big number whose value is the value of this Big number minus n.
*
* @throws `NaN` if n is invalid.
*/
minus(n: BigSource): Big;
/**
* Returns a Big number whose value is the value of this Big number modulo n, i.e. the integer remainder of dividing this Big number by n.
*
* The result will have the same sign as this Big number, and it will match that of Javascript's % operator (within the limits of its precision) and BigDecimal's remainder method.
*
* @throws `NaN` if n is negative or otherwise invalid.
*/
mod(n: BigSource): Big;
/**
* Returns a Big number whose value is the value of this Big number times n - alias for .times().
*
* @throws `NaN` if n is invalid.
*/
mul(n: BigSource): Big;
/**
* Return a new Big whose value is the value of this Big negated.
*/
neg(): Big;
/**
* Returns a Big number whose value is the value of this Big number plus n.
*
* @throws `NaN` if n is invalid.
*/
plus(n: BigSource): Big;
/**
* Returns a Big number whose value is the value of this Big number raised to the power exp.
*
* If exp is negative and the result has more fraction digits than is specified by Big.DP, it will be rounded to Big.DP decimal places using rounding mode Big.RM.
*
* @param exp The power to raise the number to, -1e 6 to 1e 6 inclusive
* @throws `!pow!` if exp is invalid.
*
* Note: High value exponents may cause this method to be slow to return.
*/
pow(exp: number): Big;
/**
* Return a new Big whose value is the value of this Big rounded to a maximum precision of sd
* significant digits using rounding mode rm, or Big.RM if rm is not specified.
*
* @param sd Significant digits: integer, 1 to MAX_DP inclusive.
* @param rm Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
* @throws `!prec!` if sd is invalid.
* @throws `!Big.RM!` if rm is invalid.
*/
prec(sd: number, rm?: RoundingMode): Big;
/**
* Returns a Big number whose value is the value of this Big number rounded using rounding mode rm to a maximum of dp decimal places.
*
* @param dp Decimal places, 0 to 1e 6 inclusive
* @param rm Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
* @throws `!round!` if dp is invalid.
* @throws `!Big.RM!` if rm is invalid.
*/
round(dp?: number, rm?: RoundingMode): Big;
/**
* Returns a Big number whose value is the square root of this Big number.
*
* If the result has more fraction digits than is specified by Big.DP, it will be rounded to Big.DP decimal places using rounding mode Big.RM.
*
* @throws `NaN` if this Big number is negative.
*/
sqrt(): Big;
/**
* Returns a Big number whose value is the value of this Big number minus n - alias for .minus().
*
* @throws `NaN` if n is invalid.
*/
sub(n: BigSource): Big;
/**
* Returns a Big number whose value is the value of this Big number times n.
*
* @throws `NaN` if n is invalid.
*/
times(n: BigSource): Big;
/**
* Returns a string representing the value of this Big number in exponential notation to a fixed number of decimal places dp.
*
* If the value of this Big number in exponential notation has more digits to the right of the decimal point than is specified by dp,
* the return value will be rounded to dp decimal places using rounding mode Big.RM.
*
* If the value of this Big number in exponential notation has fewer digits to the right of the decimal point than is specified by dp, the return value will be appended with zeros accordingly.
*
* If dp is omitted, or is null or undefined, the number of digits after the decimal point defaults to the minimum number of digits necessary to represent the value exactly.
*
* @param dp Decimal places, 0 to 1e 6 inclusive
* @param rm Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
* @throws `!toFix!` if dp is invalid.
*/
toExponential(dp?: number, rm?: RoundingMode): string;
/**
* Returns a string representing the value of this Big number in normal notation to a fixed number of decimal places dp.
*
* If the value of this Big number in normal notation has more digits to the right of the decimal point than is specified by dp,
* the return value will be rounded to dp decimal places using rounding mode Big.RM.
*
* If the value of this Big number in normal notation has fewer fraction digits then is specified by dp, the return value will be appended with zeros accordingly.
*
* Unlike Number.prototype.toFixed, which returns exponential notation if a number is greater or equal to 1021, this method will always return normal notation.
*
* If dp is omitted, or is null or undefined, then the return value is simply the value in normal notation.
* This is also unlike Number.prototype.toFixed, which returns the value to zero decimal places.
*
* @param dp Decimal places, 0 to 1e 6 inclusive
* @param rm Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
* @throws `!toFix!` if dp is invalid.
*/
toFixed(dp?: number, rm?: RoundingMode): string;
/**
* Returns a string representing the value of this Big number to the specified number of significant digits sd.
*
* If the value of this Big number has more digits than is specified by sd, the return value will be rounded to sd significant digits using rounding mode Big.RM.
*
* If the value of this Big number has fewer digits than is specified by sd, the return value will be appended with zeros accordingly.
*
* If sd is less than the number of digits necessary to represent the integer part of the value in normal notation, then exponential notation is used.
*
* If sd is omitted, or is null or undefined, then the return value is the same as .toString().
*
* @param sd Significant digits, 1 to 1e 6 inclusive
* @param rm Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
* @throws `!toPre!` if sd is invalid.
*/
toPrecision(sd?: number, rm?: RoundingMode): string;
/**
* Returns a string representing the value of this Big number.
*
* If this Big number has a positive exponent that is equal to or greater than 21, or a negative exponent equal to or less than -7, then exponential notation is returned.
*
* The point at which toString returns exponential rather than normal notation can be adjusted by changing
* the value of Big.E_POS and Big.E_NEG. By default, Big numbers correspond to Javascript's number type in this regard.
*/
toString(): string;
/**
* Returns a primitive number representing the value of this Big number.
*
* If Big.strict is true an error will be thrown if toNumber is called on a Big number which cannot be converted to a primitive number without a loss of precision.
*
* @since 6.0
*/
toNumber(): number;
/**
* Returns a string representing the value of this Big number.
*
* If this Big number has a positive exponent that is equal to or greater than 21, or a negative exponent equal to or less than -7, then exponential notation is returned.
*
* The point at which toString returns exponential rather than normal notation can be adjusted by changing
* the value of Big.E_POS and Big.E_NEG. By default, Big numbers correspond to Javascript's number type in this regard.
*/
valueOf(): string;
/**
* Returns a string representing the value of this Big number.
*
* If this Big number has a positive exponent that is equal to or greater than 21, or a negative exponent equal to or less than -7, then exponential notation is returned.
*
* The point at which toString returns exponential rather than normal notation can be adjusted by changing
* the value of Big.E_POS and Big.E_NEG. By default, Big numbers correspond to Javascript's number type in this regard.
*/
toJSON(): string;
/**
* Returns an array of single digits
*/
c: number[];
/**
* Returns the exponent, Integer, -1e 6 to 1e 6 inclusive
*/
e: number;
/**
* Returns the sign, -1 or 1
*/
s: number;
}
}
// We want the exported symbol 'Big' to represent two things:
// - The Big interface, when used in a type context.
// - The BigConstructor instance, when used in a value context.
declare const Big: Big.BigConstructor;
type Big = Big.Big;
// The export is the same as type/value combo symbol 'Big'.
export = Big;
export as namespace Big;