• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Type definitions for decimal.js >=7.0.0
2// Project: https://github.com/MikeMcl/decimal.js
3// Definitions by: Michael Mclaughlin <https://github.com/MikeMcl>
4// Definitions: https://github.com/MikeMcl/decimal.js
5//
6// Documentation: http://mikemcl.github.io/decimal.js/
7//
8// Exports (available globally or when using import):
9//
10//   class     Decimal (default export)
11//   type      Decimal.Constructor
12//   type      Decimal.Instance
13//   type      Decimal.Modulo
14//   type      Decimal.Rounding
15//   type      Decimal.Value
16//   interface Decimal.Config
17//
18// Example (alternative syntax commented-out):
19//
20//   import {Decimal} from "decimal.js"
21//   //import Decimal from "decimal.js"
22//
23//   let r: Decimal.Rounding = Decimal.ROUND_UP;
24//   let c: Decimal.Configuration = {precision: 4, rounding: r};
25//   Decimal.set(c);
26//   let v: Decimal.Value = '12345.6789';
27//   let d: Decimal = new Decimal(v);
28//   //let d: Decimal.Instance = new Decimal(v);
29//
30// The use of compiler option `--strictNullChecks` is recommended.
31
32export default Decimal;
33
34export namespace Decimal {
35  export type Config = DecimalConfig;
36  export type Constructor = DecimalConstructor;
37  export type Instance = DecimalInstance;
38  export type Modulo = DecimalModulo;
39  export type Rounding = DecimalRounding;
40  export type Value = DecimalValue;
41}
42
43declare global {
44  const Decimal: DecimalConstructor;
45  type Decimal = DecimalInstance;
46
47  namespace Decimal {
48    type Config = DecimalConfig;
49    type Constructor = DecimalConstructor;
50    type Instance = DecimalInstance;
51    type Modulo = DecimalModulo;
52    type Rounding = DecimalRounding;
53    type Value = DecimalValue;
54  }
55}
56
57type DecimalInstance = Decimal;
58type DecimalConstructor = typeof Decimal;
59type DecimalValue = string | number | Decimal;
60type DecimalRounding = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
61type DecimalModulo = DecimalRounding | 9;
62
63// http://mikemcl.github.io/decimal.js/#constructor-properties
64interface DecimalConfig {
65  precision?: number;
66  rounding?: DecimalRounding;
67  toExpNeg?: number;
68  toExpPos?: number;
69  minE?: number;
70  maxE?: number;
71  crypto?: boolean;
72  modulo?: DecimalModulo;
73  defaults?: boolean;
74}
75
76export declare class Decimal {
77  readonly d: number[];
78  readonly e: number;
79  readonly s: number;
80
81  constructor(n: DecimalValue);
82
83  absoluteValue(): Decimal;
84  abs(): Decimal;
85
86  ceil(): Decimal;
87
88  clampedTo(min: Decimal.Value, max: Decimal.Value): Decimal;
89  clamp(min: Decimal.Value, max: Decimal.Value): Decimal;
90
91  comparedTo(n: DecimalValue): number;
92  cmp(n: DecimalValue): number;
93
94  cosine(): Decimal;
95  cos(): Decimal;
96
97  cubeRoot(): Decimal;
98  cbrt(): Decimal;
99
100  decimalPlaces(): number;
101  dp(): number;
102
103  dividedBy(n: DecimalValue): Decimal;
104  div(n: DecimalValue): Decimal;
105
106  dividedToIntegerBy(n: DecimalValue): Decimal;
107  divToInt(n: DecimalValue): Decimal;
108
109  equals(n: DecimalValue): boolean;
110  eq(n: DecimalValue): boolean;
111
112  floor(): Decimal;
113
114  greaterThan(n: DecimalValue): boolean;
115  gt(n: DecimalValue): boolean;
116
117  greaterThanOrEqualTo(n: DecimalValue): boolean;
118  gte(n: DecimalValue): boolean;
119
120  hyperbolicCosine(): Decimal;
121  cosh(): Decimal;
122
123  hyperbolicSine(): Decimal;
124  sinh(): Decimal;
125
126  hyperbolicTangent(): Decimal;
127  tanh(): Decimal;
128
129  inverseCosine(): Decimal;
130  acos(): Decimal;
131
132  inverseHyperbolicCosine(): Decimal;
133  acosh(): Decimal;
134
135  inverseHyperbolicSine(): Decimal;
136  asinh(): Decimal;
137
138  inverseHyperbolicTangent(): Decimal;
139  atanh(): Decimal;
140
141  inverseSine(): Decimal;
142  asin(): Decimal;
143
144  inverseTangent(): Decimal;
145  atan(): Decimal;
146
147  isFinite(): boolean;
148
149  isInteger(): boolean;
150  isInt(): boolean;
151
152  isNaN(): boolean;
153
154  isNegative(): boolean;
155  isNeg(): boolean;
156
157  isPositive(): boolean;
158  isPos(): boolean;
159
160  isZero(): boolean;
161
162  lessThan(n: DecimalValue): boolean;
163  lt(n: DecimalValue): boolean;
164
165  lessThanOrEqualTo(n: DecimalValue): boolean;
166  lte(n: DecimalValue): boolean;
167
168  logarithm(n?: DecimalValue): Decimal;
169  log(n?: DecimalValue): Decimal;
170
171  minus(n: DecimalValue): Decimal;
172  sub(n: DecimalValue): Decimal;
173
174  modulo(n: DecimalValue): Decimal;
175  mod(n: DecimalValue): Decimal;
176
177  naturalExponential(): Decimal;
178  exp(): Decimal;
179
180  naturalLogarithm(): Decimal;
181  ln(): Decimal;
182
183  negated(): Decimal;
184  neg(): Decimal;
185
186  plus(n: DecimalValue): Decimal;
187  add(n: DecimalValue): Decimal;
188
189  precision(includeZeros?: boolean): number;
190  sd(includeZeros?: boolean): number;
191
192  round(): Decimal;
193
194  sine() : Decimal;
195  sin() : Decimal;
196
197  squareRoot(): Decimal;
198  sqrt(): Decimal;
199
200  tangent() : Decimal;
201  tan() : Decimal;
202
203  times(n: DecimalValue): Decimal;
204  mul(n: DecimalValue) : Decimal;
205
206  toBinary(significantDigits?: number): string;
207  toBinary(significantDigits: number, rounding: DecimalRounding): string;
208
209  toDecimalPlaces(decimalPlaces?: number): Decimal;
210  toDecimalPlaces(decimalPlaces: number, rounding: DecimalRounding): Decimal;
211  toDP(decimalPlaces?: number): Decimal;
212  toDP(decimalPlaces: number, rounding: DecimalRounding): Decimal;
213
214  toExponential(decimalPlaces?: number): string;
215  toExponential(decimalPlaces: number, rounding: DecimalRounding): string;
216
217  toFixed(decimalPlaces?: number): string;
218  toFixed(decimalPlaces: number, rounding: DecimalRounding): string;
219
220  toFraction(max_denominator?: DecimalValue): Decimal[];
221
222  toHexadecimal(significantDigits?: number): string;
223  toHexadecimal(significantDigits: number, rounding: DecimalRounding): string;
224  toHex(significantDigits?: number): string;
225  toHex(significantDigits: number, rounding?: DecimalRounding): string;
226
227  toJSON(): string;
228
229  toNearest(n: DecimalValue, rounding?: DecimalRounding): Decimal;
230
231  toNumber(): number;
232
233  toOctal(significantDigits?: number): string;
234  toOctal(significantDigits: number, rounding: DecimalRounding): string;
235
236  toPower(n: DecimalValue): Decimal;
237  pow(n: DecimalValue): Decimal;
238
239  toPrecision(significantDigits?: number): string;
240  toPrecision(significantDigits: number, rounding: DecimalRounding): string;
241
242  toSignificantDigits(significantDigits?: number): Decimal;
243  toSignificantDigits(significantDigits: number, rounding: DecimalRounding): Decimal;
244  toSD(significantDigits?: number): Decimal;
245  toSD(significantDigits: number, rounding: DecimalRounding): Decimal;
246
247  toString(): string;
248
249  truncated(): Decimal;
250  trunc(): Decimal;
251
252  valueOf(): string;
253
254  static abs(n: DecimalValue): Decimal;
255  static acos(n: DecimalValue): Decimal;
256  static acosh(n: DecimalValue): Decimal;
257  static add(x: DecimalValue, y: DecimalValue): Decimal;
258  static asin(n: DecimalValue): Decimal;
259  static asinh(n: DecimalValue): Decimal;
260  static atan(n: DecimalValue): Decimal;
261  static atanh(n: DecimalValue): Decimal;
262  static atan2(y: DecimalValue, x: DecimalValue): Decimal;
263  static cbrt(n: DecimalValue): Decimal;
264  static ceil(n: DecimalValue): Decimal;
265  static clamp(n: Decimal.Value, min: Decimal.Value, max: Decimal.Value): Decimal;
266  static clone(object?: DecimalConfig): DecimalConstructor;
267  static config(object: DecimalConfig): DecimalConstructor;
268  static cos(n: DecimalValue): Decimal;
269  static cosh(n: DecimalValue): Decimal;
270  static div(x: DecimalValue, y: DecimalValue): Decimal;
271  static exp(n: DecimalValue): Decimal;
272  static floor(n: DecimalValue): Decimal;
273  static hypot(...n: DecimalValue[]): Decimal;
274  static isDecimal(object: any): object is Decimal;
275  static ln(n: DecimalValue): Decimal;
276  static log(n: DecimalValue, base?: DecimalValue): Decimal;
277  static log2(n: DecimalValue): Decimal;
278  static log10(n: DecimalValue): Decimal;
279  static max(...n: DecimalValue[]): Decimal;
280  static min(...n: DecimalValue[]): Decimal;
281  static mod(x: DecimalValue, y: DecimalValue): Decimal;
282  static mul(x: DecimalValue, y: DecimalValue): Decimal;
283  static noConflict(): DecimalConstructor;   // Browser only
284  static pow(base: DecimalValue, exponent: DecimalValue): Decimal;
285  static random(significantDigits?: number): Decimal;
286  static round(n: DecimalValue): Decimal;
287  static set(object: DecimalConfig): DecimalConstructor;
288  static sign(n: DecimalValue): number;
289  static sin(n: DecimalValue): Decimal;
290  static sinh(n: DecimalValue): Decimal;
291  static sqrt(n: DecimalValue): Decimal;
292  static sub(x: DecimalValue, y: DecimalValue): Decimal;
293  static sum(...n: Decimal.Value[]): Decimal;
294  static tan(n: DecimalValue): Decimal;
295  static tanh(n: DecimalValue): Decimal;
296  static trunc(n: DecimalValue): Decimal;
297
298  static readonly default?: DecimalConstructor;
299  static readonly Decimal?: DecimalConstructor;
300
301  static readonly precision: number;
302  static readonly rounding: DecimalRounding;
303  static readonly toExpNeg: number;
304  static readonly toExpPos: number;
305  static readonly minE: number;
306  static readonly maxE: number;
307  static readonly crypto: boolean;
308  static readonly modulo: DecimalModulo;
309
310  static readonly ROUND_UP: 0;
311  static readonly ROUND_DOWN: 1;
312  static readonly ROUND_CEIL: 2;
313  static readonly ROUND_FLOOR: 3;
314  static readonly ROUND_HALF_UP: 4;
315  static readonly ROUND_HALF_DOWN: 5;
316  static readonly ROUND_HALF_EVEN: 6;
317  static readonly ROUND_HALF_CEIL: 7;
318  static readonly ROUND_HALF_FLOOR: 8;
319  static readonly EUCLID: 9;
320}
321