decimal.d.ts 8.5 KB

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