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