decimal.global.d.ts 9.0 KB

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