forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
big.js.d.ts
203 lines (171 loc) · 11.6 KB
/
big.js.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
// Type definitions for big.js
// Project: https://github.com/MikeMcl/big.js/
// Definitions by: Steve Ognibene <https://github.com/nycdotnet/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module BigJsLibrary {
export const enum RoundingMode {
RoundTowardsZero = 0,
RoundTowardsNearestAwayFromZero = 1,
RoundTowardsNearestTowardsEven = 2,
RoundAwayFromZero = 3
}
interface BigJS extends BigJS_Constructors {
/** 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.
@default 40 */
DP: number;
/** The rounding mode used in the above operations and by round, toExponential, toFixed and toPrecision.
Default is RoundTowardsNearestAwayFromZero
@default 1 */
RM: RoundingMode;
}
interface BigJS_Constructors {
/** A decimal value. */
new (value: number): BigJS;
/** A decimal value.
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. */
new (value: string): BigJS;
/** A decimal value. */
new (value: BigJS): BigJS;
/** A decimal value. */
(value: number): BigJS;
/** A decimal value.
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. */
(value: string): BigJS;
/** A decimal value. */
(value: BigJS): BigJS;
/** A decimal value. */
(): BigJS;
}
/** BigJS instance methods */
interface BigJS extends BigJS_Constructors {
/** Returns a Big number whose value is the absolute value, i.e. the magnitude, of this Big number. */
abs(): BigJS;
/** Compare
@returns {Number}
1 = If the value of this Big number is greater than the value of n
-1 = If the value of this Big number is less than the value of n
0 = If this Big number and n have the same value */
cmp(n: number): number;
/** Compare
@returns {Number}
1 = If the value of this Big number is greater than the value of n
-1 = If the value of this Big number is less than the value of n
0 = If this Big number and n have the same value */
cmp(n: string): number;
/** Compare
@returns {Number}
1 = If the value of this Big number is greater than the value of n
-1 = If the value of this Big number is less than the value of n
0 = If this Big number and n have the same value */
cmp(n: BigJS): number;
/** Returns a Big number whose value is the value of this Big number divided by n. */
div(n: number): BigJS;
/** Returns a Big number whose value is the value of this Big number divided by n. */
div(n: string): BigJS;
/** Returns a Big number whose value is the value of this Big number divided by n. */
div(n: BigJS): BigJS;
/** Returns true if the value of this Big equals the value of n, otherwise returns false. */
eq(n: number): boolean;
/** Returns true if the value of this Big equals the value of n, otherwise returns false. */
eq(n: string): boolean;
/** Returns true if the value of this Big equals the value of n, otherwise returns false. */
eq(n: BigJS): boolean;
/** Returns true if the value of this Big is greater than the value of n, otherwise returns false. */
gt(n: number): boolean;
/** Returns true if the value of this Big is greater than the value of n, otherwise returns false. */
gt(n: string): boolean;
/** Returns true if the value of this Big is greater than the value of n, otherwise returns false. */
gt(n: BigJS): boolean;
/** Returns true if the value of this Big is greater than or equal to the value of n, otherwise returns false. */
gte(n: number): boolean;
/** Returns true if the value of this Big is greater than or equal to the value of n, otherwise returns false. */
gte(n: string): boolean;
/** Returns true if the value of this Big is greater than or equal to the value of n, otherwise returns false. */
gte(n: BigJS): boolean;
/** Returns true if the value of this Big is less than the value of n, otherwise returns false. */
lt(n: number): boolean;
/** Returns true if the value of this Big is less than the value of n, otherwise returns false. */
lt(n: string): boolean;
/** Returns true if the value of this Big is less than the value of n, otherwise returns false. */
lt(n: BigJS): boolean;
/** Returns true if the value of this Big is less than or equal to the value of n, otherwise returns false. */
lte(n: number): boolean;
/** Returns true if the value of this Big is less than or equal to the value of n, otherwise returns false. */
lte(n: string): boolean;
/** Returns true if the value of this Big is less than or equal to the value of n, otherwise returns false. */
lte(n: BigJS): boolean;
/** Returns a Big number whose value is the value of this Big number minus n. */
minus(n: number): BigJS;
/** Returns a Big number whose value is the value of this Big number minus n. */
minus(n: string): BigJS;
/** Returns a Big number whose value is the value of this Big number minus n. */
minus(n: BigJS): BigJS;
/** 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. */
mod(n: number): BigJS;
/** 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. */
mod(n: string): BigJS;
/** 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. */
mod(n: BigJS): BigJS;
/** Returns a Big number whose value is the value of this Big number plus n. */
plus(n: number): BigJS;
/** Returns a Big number whose value is the value of this Big number plus n. */
plus(n: string): BigJS;
/** Returns a Big number whose value is the value of this Big number plus n. */
plus(n: BigJS): BigJS;
/** 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 integer, -1e+6 to 1e+6 inclusive */
pow(exp: number): BigJS;
/** Returns a Big number whose value is the value of this Big number rounded to a whole number. */
round(): BigJS;
/** 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 Number of decimal places (0 to 1e+6 inclusive). If dp is omitted or is null or undefined, the return value is n rounded to a whole number. */
round(dp: number): BigJS;
/** 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 Number of decimal places (0 to 1e+6 inclusive). If dp is omitted or is null or undefined, the return value is n rounded to a whole number.
@param rm Rounding mode. If rm is omitted or is null or undefined, the current Big.RM setting is used. */
round(dp: number, rm: RoundingMode): BigJS;
/** Returns a Big number whose value is the square root of this Big number. */
sqrt(): BigJS;
/** Returns a Big number whose value is the value of this Big number times n. */
times(n: number): BigJS;
/** Returns a Big number whose value is the value of this Big number times n. */
times(n: string): BigJS;
/** Returns a Big number whose value is the value of this Big number times n. */
times(n: BigJS): BigJS;
/** Returns a string representing the value of this Big number in exponential notation to a fixed number of decimal places dp. */
toExponential(): string;
/** Returns a string representing the value of this Big number in exponential notation to a fixed number of decimal places dp.
@param dp Number of decimal places (0 to 1e+6 inclusive). 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. */
toExponential(dp: number): string;
/** Returns a string representing the value of this Big number in normal notation to a fixed number of decimal places dp. */
toFixed(): string;
/** Returns a string representing the value of this Big number in normal notation to a fixed number of decimal places dp.
@param dp Number of decimal places (0 to 1e+6 inclusive). 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. */
toFixed(dp: number): string;
/** Returns a string representing the value of this Big number to the specified number of significant digits sd. */
toPrecision(): string;
/** Returns a string representing the value of this Big number to the specified number of significant digits sd.
@param sd significant digits. If sd is omitted, or is null or undefined, then the return value is the same as .toString(). */
toPrecision(sd: number /** number of significant digits (0 to 1e+6 inclusive) */): string;
/** Returns a string representing the value of this Big number. */
toString(): string;
/** As toString. */
valueOf(): string;
/** As toString. */
toJSON(): string;
/** coefficient (significand) */
c: number[];
/** exponent (Integer, -1e+6 to 1e+6 inclusive) */
e: number;
/** sign (-1 or 1) */
s: number;
}
}
declare var Big: BigJsLibrary.BigJS;