mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-12 11:51:10 +08:00
Add type definitions for 'bignumber.js'
This commit is contained in:
445
bignumber.js/bignumber.js-tests.ts
Normal file
445
bignumber.js/bignumber.js-tests.ts
Normal file
@@ -0,0 +1,445 @@
|
||||
var x = new BigNumber(9)
|
||||
var y = new BigNumber(x)
|
||||
|
||||
BigNumber(435.345)
|
||||
|
||||
new BigNumber('5032485723458348569331745.33434346346912144534543')
|
||||
new BigNumber('4.321e+4')
|
||||
new BigNumber('-735.0918e-430')
|
||||
new BigNumber(Infinity)
|
||||
new BigNumber(NaN)
|
||||
new BigNumber('.5')
|
||||
new BigNumber('+2')
|
||||
new BigNumber(-10110100.1, 2)
|
||||
new BigNumber(-0b10110100)
|
||||
new BigNumber('123412421.234324', 5)
|
||||
new BigNumber('ff.8', 16)
|
||||
new BigNumber('0xff.8')
|
||||
|
||||
new BigNumber(9, 2)
|
||||
|
||||
new BigNumber(96517860459076817.4395)
|
||||
|
||||
new BigNumber('blurgh')
|
||||
|
||||
BigNumber.config({ DECIMAL_PLACES: 5 })
|
||||
new BigNumber(1.23456789)
|
||||
new BigNumber(1.23456789, 10)
|
||||
|
||||
BigNumber.config({ DECIMAL_PLACES: 5 })
|
||||
var BN = BigNumber.another({ DECIMAL_PLACES: 9 })
|
||||
|
||||
x = new BigNumber(1)
|
||||
y = new BN(1)
|
||||
|
||||
x.div(3)
|
||||
y.div(3)
|
||||
|
||||
BN = BigNumber.another()
|
||||
BN.config({ DECIMAL_PLACES: 9 })
|
||||
|
||||
BigNumber.config({ DECIMAL_PLACES: 5 })
|
||||
BigNumber.set({ DECIMAL_PLACES: 5 })
|
||||
BigNumber.config(5)
|
||||
|
||||
BigNumber.config({ ROUNDING_MODE: 0 })
|
||||
BigNumber.config(undefined, BigNumber.ROUND_UP)
|
||||
|
||||
BigNumber.config({ EXPONENTIAL_AT: 2 })
|
||||
new BigNumber(12.3)
|
||||
new BigNumber(123)
|
||||
new BigNumber(0.123)
|
||||
new BigNumber(0.0123)
|
||||
|
||||
BigNumber.config({ EXPONENTIAL_AT: [-7, 20] })
|
||||
new BigNumber(123456789)
|
||||
new BigNumber(0.000000123)
|
||||
|
||||
BigNumber.config({ EXPONENTIAL_AT: 1e+9 })
|
||||
|
||||
BigNumber.config({ EXPONENTIAL_AT: 0 })
|
||||
|
||||
BigNumber.config({ RANGE: 500 })
|
||||
BigNumber.config().RANGE
|
||||
new BigNumber('9.999e499')
|
||||
new BigNumber('1e500')
|
||||
new BigNumber('1e-499')
|
||||
new BigNumber('1e-500')
|
||||
|
||||
BigNumber.config({ RANGE: [-3, 4] })
|
||||
new BigNumber(99999)
|
||||
new BigNumber(100000)
|
||||
new BigNumber(0.001)
|
||||
new BigNumber(0.0001)
|
||||
|
||||
BigNumber.config({ ERRORS: false })
|
||||
|
||||
BigNumber.config({ CRYPTO: true })
|
||||
BigNumber.config().CRYPTO
|
||||
BigNumber.random()
|
||||
|
||||
BigNumber.config({ MODULO_MODE: BigNumber.EUCLID })
|
||||
BigNumber.config({ MODULO_MODE: 9 })
|
||||
|
||||
BigNumber.config({ POW_PRECISION: 100 })
|
||||
|
||||
BigNumber.config({
|
||||
FORMAT: {
|
||||
decimalSeparator: '.',
|
||||
groupSeparator: ',',
|
||||
groupSize: 3,
|
||||
secondaryGroupSize: 0,
|
||||
fractionGroupSeparator: ' ',
|
||||
fractionGroupSize: 0
|
||||
}
|
||||
});
|
||||
|
||||
BigNumber.config({
|
||||
DECIMAL_PLACES: 40,
|
||||
ROUNDING_MODE: BigNumber.ROUND_HALF_CEIL,
|
||||
EXPONENTIAL_AT: [-10, 20],
|
||||
RANGE: [-500, 500],
|
||||
ERRORS: true,
|
||||
CRYPTO: true,
|
||||
MODULO_MODE: BigNumber.ROUND_FLOOR,
|
||||
POW_PRECISION: 80,
|
||||
FORMAT: {
|
||||
groupSize: 3,
|
||||
groupSeparator: ' ',
|
||||
decimalSeparator: ','
|
||||
}
|
||||
});
|
||||
|
||||
BigNumber.config(40, 7, [-10, 20], 500, 1, 1, 3, 80)
|
||||
|
||||
var obj = BigNumber.config();
|
||||
obj.ERRORS
|
||||
obj.RANGE
|
||||
|
||||
x = new BigNumber('3257869345.0378653')
|
||||
BigNumber.max(4e9, x, '123456789.9')
|
||||
|
||||
var arr = [12, '13', new BigNumber(14)]
|
||||
BigNumber.max(arr)
|
||||
|
||||
x = new BigNumber('3257869345.0378653')
|
||||
BigNumber.min(4e9, x, '123456789.9')
|
||||
|
||||
arr = [2, new BigNumber(-14), '-15.9999', -12]
|
||||
BigNumber.min(arr)
|
||||
|
||||
BigNumber.config({ DECIMAL_PLACES: 10 })
|
||||
BigNumber.random()
|
||||
BigNumber.random(20)
|
||||
|
||||
BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_CEIL })
|
||||
BigNumber.config({ ROUNDING_MODE: 2 })
|
||||
|
||||
x = new BigNumber(-0.8)
|
||||
y = x.absoluteValue()
|
||||
var z = y.abs()
|
||||
|
||||
x = new BigNumber(1.3)
|
||||
x.ceil()
|
||||
y = new BigNumber(-1.8)
|
||||
y.ceil()
|
||||
|
||||
x = new BigNumber(Infinity)
|
||||
y = new BigNumber(5)
|
||||
x.comparedTo(y)
|
||||
x.comparedTo(x.minus(1))
|
||||
y.cmp(NaN)
|
||||
y.cmp('110', 2)
|
||||
|
||||
x = new BigNumber(123.45)
|
||||
x.decimalPlaces()
|
||||
y = new BigNumber('9.9e-101')
|
||||
y.dp()
|
||||
|
||||
x = new BigNumber(355)
|
||||
y = new BigNumber(113)
|
||||
x.dividedBy(y)
|
||||
x.div(5)
|
||||
x.div(47, 16)
|
||||
|
||||
x = new BigNumber(5)
|
||||
y = new BigNumber(3)
|
||||
x.dividedToIntegerBy(y)
|
||||
x.divToInt(0.7)
|
||||
x.divToInt('0.f', 16)
|
||||
|
||||
0 === 1e-324
|
||||
x = new BigNumber(0)
|
||||
x.equals('1e-324')
|
||||
BigNumber(-0).eq(x)
|
||||
BigNumber(255).eq('ff', 16)
|
||||
|
||||
y = new BigNumber(NaN)
|
||||
y.equals(NaN)
|
||||
|
||||
x = new BigNumber(1.8)
|
||||
x.floor()
|
||||
y = new BigNumber(-1.3)
|
||||
y.floor()
|
||||
|
||||
0.1 > (0.3 - 0.2)
|
||||
x = new BigNumber(0.1)
|
||||
x.greaterThan(BigNumber(0.3).minus(0.2))
|
||||
BigNumber(0).gt(x)
|
||||
BigNumber(11, 3).gt(11.1, 2)
|
||||
|
||||
x = new BigNumber(0.3).minus(0.2)
|
||||
x.greaterThanOrEqualTo(0.1)
|
||||
BigNumber(1).gte(x)
|
||||
BigNumber(10, 18).gte('i', 36)
|
||||
|
||||
x = new BigNumber(1)
|
||||
x.isFinite()
|
||||
y = new BigNumber(Infinity)
|
||||
y.isFinite()
|
||||
|
||||
x = new BigNumber(1)
|
||||
x.isInteger()
|
||||
y = new BigNumber(123.456)
|
||||
y.isInt()
|
||||
|
||||
x = new BigNumber(NaN)
|
||||
x.isNaN()
|
||||
y = new BigNumber('Infinity')
|
||||
y.isNaN()
|
||||
|
||||
x = new BigNumber(-0)
|
||||
x.isNegative()
|
||||
y = new BigNumber(2)
|
||||
y.isNeg()
|
||||
|
||||
x = new BigNumber(-0)
|
||||
x.isZero() && x.isNeg()
|
||||
y = new BigNumber(Infinity)
|
||||
y.isZero()
|
||||
|
||||
x = new BigNumber(0.3).minus(0.2)
|
||||
x.lessThan(0.1)
|
||||
BigNumber(0).lt(x)
|
||||
BigNumber(11.1, 2).lt(11, 3)
|
||||
|
||||
x = new BigNumber(0.1)
|
||||
x.lessThanOrEqualTo(BigNumber(0.3).minus(0.2))
|
||||
BigNumber(-1).lte(x)
|
||||
BigNumber(10, 18).lte('i', 36)
|
||||
|
||||
x = new BigNumber(0.3)
|
||||
x.minus(0.1)
|
||||
x.sub(0.6, 20)
|
||||
|
||||
x = new BigNumber(1)
|
||||
x.modulo(0.9)
|
||||
y = new BigNumber(33)
|
||||
y.mod('a', 33)
|
||||
|
||||
x = new BigNumber(1.8)
|
||||
x.negated()
|
||||
y = new BigNumber(-1.3)
|
||||
y.neg()
|
||||
|
||||
x = new BigNumber(0.1)
|
||||
y = x.plus(0.2)
|
||||
BigNumber(0.7).plus(x).add(y)
|
||||
x.plus('0.1', 8)
|
||||
|
||||
x = new BigNumber(1.234)
|
||||
x.precision()
|
||||
y = new BigNumber(987000)
|
||||
y.sd()
|
||||
y.sd(true)
|
||||
|
||||
y = new BigNumber(x)
|
||||
y.round()
|
||||
y.round(1)
|
||||
y.round(2)
|
||||
y.round(10)
|
||||
y.round(0, 1)
|
||||
y.round(0, 6)
|
||||
y.round(1, 1)
|
||||
y.round(1, BigNumber.ROUND_HALF_EVEN)
|
||||
y
|
||||
|
||||
x = new BigNumber(1.23)
|
||||
x.shift(3)
|
||||
x.shift(-3)
|
||||
|
||||
x = new BigNumber(16)
|
||||
x.squareRoot()
|
||||
y = new BigNumber(3)
|
||||
y.sqrt()
|
||||
|
||||
x = new BigNumber(0.6)
|
||||
y = x.times(3)
|
||||
BigNumber('7e+500').times(y)
|
||||
x.times('-a', 16)
|
||||
|
||||
BigNumber.config({ DECIMAL_PLACES: 5, ROUNDING_MODE: 4 })
|
||||
x = new BigNumber(9876.54321)
|
||||
|
||||
x.toDigits()
|
||||
x.toDigits(6)
|
||||
x.toDigits(6, BigNumber.ROUND_UP)
|
||||
x.toDigits(2)
|
||||
x.toDigits(2, 1)
|
||||
x
|
||||
|
||||
y = new BigNumber(45.6)
|
||||
y.toExponential()
|
||||
y.toExponential(0)
|
||||
y.toExponential(1)
|
||||
y.toExponential(1, 1)
|
||||
y.toExponential(3)
|
||||
|
||||
y = new BigNumber(3.456)
|
||||
y.toFixed()
|
||||
y.toFixed(0)
|
||||
y.toFixed(2)
|
||||
y.toFixed(2, 1)
|
||||
y.toFixed(5)
|
||||
|
||||
var format = {
|
||||
decimalSeparator: '.',
|
||||
groupSeparator: ',',
|
||||
groupSize: 3,
|
||||
secondaryGroupSize: 0,
|
||||
fractionGroupSeparator: ' ',
|
||||
fractionGroupSize: 0
|
||||
}
|
||||
BigNumber.config({ FORMAT: format })
|
||||
|
||||
x = new BigNumber('123456789.123456789')
|
||||
x.toFormat()
|
||||
x.toFormat(1)
|
||||
|
||||
format.groupSeparator = ' '
|
||||
format.fractionGroupSize = 5
|
||||
x.toFormat()
|
||||
|
||||
BigNumber.config({
|
||||
FORMAT: {
|
||||
decimalSeparator: ',',
|
||||
groupSeparator: '.',
|
||||
groupSize: 3,
|
||||
secondaryGroupSize: 2
|
||||
}
|
||||
})
|
||||
|
||||
x.toFormat(6)
|
||||
|
||||
x = new BigNumber(1.75)
|
||||
x.toFraction()
|
||||
|
||||
var pi = new BigNumber('3.14159265358')
|
||||
pi.toFraction()
|
||||
pi.toFraction(100000)
|
||||
pi.toFraction(10000)
|
||||
pi.toFraction(100)
|
||||
pi.toFraction(10)
|
||||
pi.toFraction(1)
|
||||
|
||||
x = new BigNumber('177.7e+457')
|
||||
y = new BigNumber(235.4325)
|
||||
z = new BigNumber('0.0098074')
|
||||
|
||||
var str = JSON.stringify([x, y, z])
|
||||
|
||||
JSON.parse(str, (key, val) => key === '' ? val : new BigNumber(val))
|
||||
|
||||
x = new BigNumber(456.789)
|
||||
x.toNumber()
|
||||
{ +x }
|
||||
|
||||
y = new BigNumber('45987349857634085409857349856430985')
|
||||
y.toNumber()
|
||||
|
||||
z = new BigNumber(-0)
|
||||
1 / +z
|
||||
1 / z.toNumber()
|
||||
|
||||
x = new BigNumber(0.7)
|
||||
x.toPower(2)
|
||||
BigNumber(3).pow(-2)
|
||||
|
||||
y = new BigNumber(45.6)
|
||||
x.toPrecision()
|
||||
y.toPrecision()
|
||||
x.toPrecision(1)
|
||||
y.toPrecision(1)
|
||||
y.toPrecision(2, 0)
|
||||
y.toPrecision(2, 1)
|
||||
x.toPrecision(5)
|
||||
y.toPrecision(5)
|
||||
|
||||
x = new BigNumber(750000)
|
||||
x.toString()
|
||||
BigNumber.config({ EXPONENTIAL_AT: 5 })
|
||||
x.toString()
|
||||
|
||||
y = new BigNumber(362.875)
|
||||
y.toString(2)
|
||||
y.toString(9)
|
||||
y.toString(32)
|
||||
|
||||
BigNumber.config({ DECIMAL_PLACES: 4 });
|
||||
z = new BigNumber('1.23456789')
|
||||
z.toString()
|
||||
z.toString(10)
|
||||
|
||||
x = new BigNumber(123.456)
|
||||
x.truncated()
|
||||
y = new BigNumber(-12.3)
|
||||
y.trunc()
|
||||
|
||||
x = new BigNumber('-0')
|
||||
x.toString()
|
||||
x.valueOf()
|
||||
y = new BigNumber('1.777e+457')
|
||||
y.valueOf()
|
||||
|
||||
x = new BigNumber(0.123)
|
||||
x.toExponential()
|
||||
x.c
|
||||
x.e
|
||||
x.s
|
||||
|
||||
z = new BigNumber('-123.4567000e+2')
|
||||
z.toExponential()
|
||||
z.c
|
||||
z.e
|
||||
z.s
|
||||
|
||||
x = new BigNumber(3)
|
||||
x instanceof BigNumber
|
||||
x.isBigNumber
|
||||
|
||||
BN = BigNumber.another();
|
||||
|
||||
y = new BN(3)
|
||||
y instanceof BigNumber
|
||||
y.isBigNumber
|
||||
|
||||
y = new BigNumber(-0)
|
||||
y.c
|
||||
y.e
|
||||
y.s
|
||||
|
||||
try {
|
||||
// ...
|
||||
} catch (e) {
|
||||
if (e instanceof Error && e.name == 'BigNumber Error') {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
x = new BigNumber("1.0")
|
||||
y = new BigNumber("1.1000")
|
||||
z = x.add(y)
|
||||
|
||||
x = new BigNumber("1.20")
|
||||
y = new BigNumber("3.45000")
|
||||
z = x.mul(y)
|
||||
693
bignumber.js/index.d.ts
vendored
Normal file
693
bignumber.js/index.d.ts
vendored
Normal file
@@ -0,0 +1,693 @@
|
||||
// Type definitions for bignumber.js 4.0
|
||||
// Project: https://github.com/MikeMcl/bignumber.js/
|
||||
// Definitions by: Viktor Smirnov <https://github.com/LaserUnicorns/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
declare var BigNumber: bignumber.BigNumberStatic;
|
||||
|
||||
export as namespace BigNumber;
|
||||
export = BigNumber;
|
||||
|
||||
declare namespace bignumber {
|
||||
|
||||
const enum RoundingMode {
|
||||
|
||||
/**
|
||||
* Rounds away from zero
|
||||
*/
|
||||
ROUND_UP = 0,
|
||||
|
||||
/**
|
||||
* Rounds towards zero
|
||||
*/
|
||||
ROUND_DOWN = 1,
|
||||
|
||||
/**
|
||||
* Rounds towards `Infinity`
|
||||
*/
|
||||
ROUND_CEIL = 2,
|
||||
|
||||
/**
|
||||
* Rounds towards `-Infinity`
|
||||
*/
|
||||
ROUND_FLOOR = 3,
|
||||
|
||||
/**
|
||||
* Rounds towards nearest neighbour.
|
||||
* If equidistant, rounds away from zero.
|
||||
*/
|
||||
ROUND_HALF_UP = 4,
|
||||
|
||||
/**
|
||||
* Rounds towards nearest neighbour.
|
||||
* If equidistant, rounds towards zero.
|
||||
*/
|
||||
ROUND_HALF_DOWN = 5,
|
||||
|
||||
/**
|
||||
* Rounds towards nearest neighbour.
|
||||
* If equidistant, rounds towards even neighbour.
|
||||
*/
|
||||
ROUND_HALF_EVEN = 6,
|
||||
|
||||
/**
|
||||
* Rounds towards nearest neighbour.
|
||||
* If equidistant, rounds towards `Infinity`.
|
||||
*/
|
||||
ROUND_HALF_CEIL = 7,
|
||||
|
||||
/**
|
||||
* Rounds towards nearest neighbour.
|
||||
* If equidistant, rounds towards `-Infinity`.
|
||||
*/
|
||||
ROUND_HALF_FLOOR = 8,
|
||||
|
||||
/**
|
||||
* The remainder is always positive.
|
||||
*
|
||||
* Euclidian division: `q = sign(n) * floor(a / abs(n))`
|
||||
*/
|
||||
EUCLID = 9,
|
||||
}
|
||||
|
||||
interface FormatConfig {
|
||||
|
||||
/**
|
||||
* The decimal separator.
|
||||
*/
|
||||
decimalSeparator: string;
|
||||
|
||||
/**
|
||||
* The grouping separator of the integer part.
|
||||
*/
|
||||
groupSeparator: string;
|
||||
|
||||
/**
|
||||
* The primary grouping size of the integer part.
|
||||
*/
|
||||
groupSize: number;
|
||||
|
||||
/**
|
||||
* The secondary grouping size of the integer part.
|
||||
*/
|
||||
secondaryGroupSize: number;
|
||||
|
||||
/**
|
||||
* The grouping separator of the fraction part.
|
||||
*/
|
||||
fractionGroupSeparator: string;
|
||||
|
||||
/**
|
||||
* The grouping size of the fraction part.
|
||||
*/
|
||||
fractionGroupSize: number;
|
||||
}
|
||||
|
||||
interface BigNumberConfig {
|
||||
|
||||
/**
|
||||
* The maximum number of decimal places of the results of operations involving division,
|
||||
* i.e. division, square root and base conversion operations, and power operations with negative exponents.
|
||||
*/
|
||||
DECIMAL_PLACES: number;
|
||||
|
||||
/**
|
||||
* The rounding mode used in the above operations and the default rounding mode of round, `toExponential`, `toFixed`, `toFormat` and `toPrecision`.
|
||||
*/
|
||||
ROUNDING_MODE: RoundingMode;
|
||||
|
||||
/**
|
||||
* The exponent value(s) at which `toString` returns exponential notation.
|
||||
*
|
||||
* If a single number is assigned, the value is the exponent magnitude.
|
||||
*
|
||||
* If an array of two numbers is assigned then the first number is the negative exponent value at and beneath which exponential notation is used,
|
||||
* and the second number is the positive exponent value at and above which the same.
|
||||
*/
|
||||
EXPONENTIAL_AT: number | number[];
|
||||
|
||||
/**
|
||||
* The exponent value(s) beyond which overflow to `Infinity` and underflow to zero occurs.
|
||||
*
|
||||
* If a single number is assigned, it is the maximum exponent magnitude:
|
||||
* values wth a positive exponent of greater magnitude become `Infinity`
|
||||
* and those with a negative exponent of greater magnitude become zero.
|
||||
*
|
||||
* If an array of two numbers is assigned then the first number is the negative exponent limit and the second number is the positive exponent limit.
|
||||
*/
|
||||
RANGE: number | number[];
|
||||
|
||||
/**
|
||||
* The value that determines whether BigNumber Errors are thrown.
|
||||
*
|
||||
* If `ERRORS` is false, no errors will be thrown.
|
||||
*/
|
||||
ERRORS: boolean | 0 | 1;
|
||||
|
||||
/**
|
||||
* The value that determines whether cryptographically-secure pseudo-random number generation is used.
|
||||
*
|
||||
* If `CRYPTO` is set to `true` then the `random` method will generate random digits using `crypto.getRandomValues` in browsers that support it,
|
||||
* or `crypto.randomBytes` if using a version of Node.js that supports it.
|
||||
*
|
||||
* If neither function is supported by the host environment then attempting to set `CRYPTO` to `true` will fail, and if `ERRORS` is `true` an exception will be thrown.
|
||||
*
|
||||
* If `CRYPTO` is `false` then the source of randomness used will be `Math.random` (which is assumed to generate at least `30` bits of randomness).
|
||||
*/
|
||||
CRYPTO: boolean | 0 | 1;
|
||||
|
||||
/**
|
||||
* The modulo mode used when calculating the modulus: `a mod n`.
|
||||
*
|
||||
* The quotient, `q = a / n`, is calculated according to the `ROUNDING_MODE` that corresponds to the chosen `MODULO_MODE`.
|
||||
*
|
||||
* The remainder, `r`, is calculated as: `r = a - n * q`.
|
||||
*/
|
||||
MODULO_MODE: RoundingMode;
|
||||
|
||||
/**
|
||||
* The maximum number of significant digits of the result of the power operation (unless a modulus is specified).
|
||||
*
|
||||
* If set to `0`, the number of signifcant digits will not be limited.
|
||||
*/
|
||||
POW_PRECISION: number;
|
||||
|
||||
/**
|
||||
* The `FORMAT` object configures the format of the string returned by the toFormat method.
|
||||
*/
|
||||
FORMAT: Partial<FormatConfig>
|
||||
}
|
||||
|
||||
type NumberLike = number | string | BigNumber;
|
||||
|
||||
interface BigNumberStatic {
|
||||
|
||||
/**
|
||||
* Returns a new instance of a BigNumber object.
|
||||
*/
|
||||
(value: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a new instance of a BigNumber object.
|
||||
*/
|
||||
new (value: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a new independent BigNumber constructor with configuration as described by obj, or with the default configuration if obj is null or undefined.
|
||||
*/
|
||||
another(obj?: Partial<BigNumberConfig>): BigNumberStatic;
|
||||
|
||||
/**
|
||||
* Configures the settings for this particular BigNumber constructor.
|
||||
*
|
||||
*/
|
||||
config(obj?: Partial<BigNumberConfig>): BigNumberConfig;
|
||||
|
||||
/**
|
||||
* Configures the settings for this particular BigNumber constructor.
|
||||
*/
|
||||
config(
|
||||
DECIMAL_PLACES?: number,
|
||||
ROUNDING_MODE?: RoundingMode,
|
||||
EXPONENTIAL_AT?: number | number[],
|
||||
RANGE?: number | number[],
|
||||
ERRORS?: boolean | 0 | 1,
|
||||
CRYPTO?: boolean | 0 | 1,
|
||||
MODULO_MODE?: RoundingMode,
|
||||
POW_PRECISION?: number
|
||||
): BigNumberConfig;
|
||||
|
||||
/**
|
||||
* Configures the settings for this particular BigNumber constructor.
|
||||
*/
|
||||
set(obj?: Partial<BigNumberConfig>): BigNumberConfig;
|
||||
|
||||
/**
|
||||
* Configures the settings for this particular BigNumber constructor.
|
||||
*/
|
||||
set(
|
||||
DECIMAL_PLACES?: number,
|
||||
ROUNDING_MODE?: RoundingMode,
|
||||
EXPONENTIAL_AT?: number | number[],
|
||||
RANGE?: number | number[],
|
||||
ERRORS?: boolean | 0 | 1,
|
||||
CRYPTO?: boolean | 0 | 1,
|
||||
MODULO_MODE?: RoundingMode,
|
||||
POW_PRECISION?: number
|
||||
): BigNumberConfig;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the maximum of `args`.
|
||||
*/
|
||||
max(...args: NumberLike[]): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the maximum of `args`.
|
||||
*/
|
||||
max(args: NumberLike[]): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the minimum of `args`.
|
||||
*/
|
||||
min(...args: NumberLike[]): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the minimum of `args`.
|
||||
*/
|
||||
min(args: NumberLike[]): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a new BigNumber with a pseudo-random value equal to or greater than `0` and less than `1`.
|
||||
*
|
||||
* The return value will have `dp` decimal places (or less if trailing zeros are produced).
|
||||
* If `dp` is omitted then the number of decimal places will default to the current `DECIMAL_PLACES` setting.
|
||||
*
|
||||
* Depending on the value of this BigNumber constructor's `CRYPTO` setting and the support for the `crypto` object in the host environment,
|
||||
* the random digits of the return value are generated by either
|
||||
* `Math.random` (fastest),
|
||||
* `crypto.getRandomValues` (Web Cryptography API in recent browsers)
|
||||
* or `crypto.randomBytes` (Node.js).
|
||||
*
|
||||
* If `CRYPTO` is `true`, i.e. one of the `crypto` methods is to be used,
|
||||
* the value of a returned BigNumber should be cryptographically-secure and statistically indistinguishable from a random value.
|
||||
*/
|
||||
random(dp?: number): BigNumber;
|
||||
|
||||
ROUND_UP: 0;
|
||||
ROUND_DOWN: 1;
|
||||
ROUND_CEIL: 2;
|
||||
ROUND_FLOOR: 3;
|
||||
ROUND_HALF_UP: 4;
|
||||
ROUND_HALF_DOWN: 5;
|
||||
ROUND_HALF_EVEN: 6;
|
||||
ROUND_HALF_CEIL: 7;
|
||||
ROUND_HALF_FLOOR: 8;
|
||||
EUCLID: 9;
|
||||
}
|
||||
|
||||
interface BigNumber {
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the absolute value, i.e. the magnitude, of the value of this BigNumber.
|
||||
*/
|
||||
absoluteValue(): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the absolute value, i.e. the magnitude, of the value of this BigNumber.
|
||||
*/
|
||||
abs(): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber rounded to a whole number in the direction of positive Infinity.
|
||||
*/
|
||||
ceil(): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns
|
||||
*
|
||||
* `1` if the value of this BigNumber is greater than the value of `n`
|
||||
*
|
||||
* `-1` if the value of this BigNumber is less than the value of `n`
|
||||
*
|
||||
* `0` if this BigNumber and `n` have the same value
|
||||
*
|
||||
* `null` if the value of either this BigNumber or `n` is `NaN`
|
||||
*/
|
||||
comparedTo(n: NumberLike, base?: number): 1 | -1 | 0 | null;
|
||||
|
||||
/**
|
||||
* Returns
|
||||
*
|
||||
* `1` if the value of this BigNumber is greater than the value of `n`
|
||||
*
|
||||
* `-1` if the value of this BigNumber is less than the value of `n`
|
||||
*
|
||||
* `0` if this BigNumber and `n` have the same value
|
||||
*
|
||||
* `null` if the value of either this BigNumber or `n` is `NaN`
|
||||
*/
|
||||
cmp(n: NumberLike, base?: number): 1 | -1 | 0 | null;
|
||||
|
||||
/**
|
||||
* Return the number of decimal places of the value of this BigNumber, or `null` if the value of this BigNumber is `±Infinity` or `NaN`.
|
||||
*/
|
||||
decimalPlaces(): number;
|
||||
|
||||
/**
|
||||
* Return the number of decimal places of the value of this BigNumber, or `null` if the value of this BigNumber is `±Infinity` or `NaN`.
|
||||
*/
|
||||
dp(): number;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber divided by `n`, rounded according to the current `DECIMAL_PLACES` and `ROUNDING_MODE` configuration.
|
||||
*/
|
||||
dividedBy(n: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber divided by `n`, rounded according to the current `DECIMAL_PLACES` and `ROUNDING_MODE` configuration.
|
||||
*/
|
||||
div(n: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Return a BigNumber whose value is the integer part of dividing the value of this BigNumber by `n`.
|
||||
*/
|
||||
dividedToIntegerBy(n: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Return a BigNumber whose value is the integer part of dividing the value of this BigNumber by `n`.
|
||||
*/
|
||||
divToInt(n: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber equals the value of `n`, otherwise returns `false`.
|
||||
*
|
||||
* As with JavaScript, `NaN` does not equal `NaN`.
|
||||
*/
|
||||
equals(n: NumberLike, base?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber equals the value of `n`, otherwise returns `false`.
|
||||
*
|
||||
* As with JavaScript, `NaN` does not equal `NaN`.
|
||||
*/
|
||||
eq(n: NumberLike, base?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber rounded to a whole number in the direction of negative `Infinity`.
|
||||
*/
|
||||
floor(): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is greater than the value of `n`, otherwise returns `false`.
|
||||
*/
|
||||
greaterThan(n: NumberLike, base?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is greater than the value of `n`, otherwise returns `false`.
|
||||
*/
|
||||
gt(n: NumberLike, base?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is greater than or equal to the value of `n`, otherwise returns `false`.
|
||||
*/
|
||||
greaterThanOrEqualTo(n: NumberLike, base?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is greater than or equal to the value of `n`, otherwise returns `false`.
|
||||
*/
|
||||
gte(n: NumberLike, base?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is a finite number, otherwise returns `false`.
|
||||
*
|
||||
* The only possible non-finite values of a BigNumber are `NaN`, `Infinity` and `-Infinity`.
|
||||
*/
|
||||
isFinite(): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is a whole number, otherwise returns `false`.
|
||||
*/
|
||||
isInteger(): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is a whole number, otherwise returns `false`.
|
||||
*/
|
||||
isInt(): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is NaN, otherwise returns `false`.
|
||||
*/
|
||||
isNaN(): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is negative, otherwise returns `false`.
|
||||
*/
|
||||
isNegative(): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is negative, otherwise returns `false`.
|
||||
*/
|
||||
isNeg(): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is zero or minus zero, otherwise returns `false`.
|
||||
*/
|
||||
isZero(): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is less than the value of `n`, otherwise returns `false`.
|
||||
*/
|
||||
lessThan(n: NumberLike, base?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is less than the value of `n`, otherwise returns `false`.
|
||||
*/
|
||||
lt(n: NumberLike, base?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is less than or equal to the value of `n`, otherwise returns
|
||||
*/
|
||||
lessThanOrEqualTo(n: NumberLike, base?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value of this BigNumber is less than or equal to the value of `n`, otherwise returns
|
||||
*/
|
||||
lte(n: NumberLike, base?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber minus `n`.
|
||||
*/
|
||||
minus(n: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber minus `n`.
|
||||
*/
|
||||
sub(n: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber modulo `n`, i.e. the integer remainder of dividing this BigNumber by `n`.
|
||||
*
|
||||
* The value returned, and in particular its sign, is dependent on the value of the `MODULO_MODE` setting of this BigNumber constructor.
|
||||
* If it is `1` (default value), the result will have the same sign as this BigNumber,
|
||||
* and it will match that of Javascript's `%` operator (within the limits of double precision) and BigDecimal's `remainder` method.
|
||||
*/
|
||||
modulo(n: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber modulo `n`, i.e. the integer remainder of dividing this BigNumber by `n`.
|
||||
*
|
||||
* The value returned, and in particular its sign, is dependent on the value of the `MODULO_MODE` setting of this BigNumber constructor.
|
||||
* If it is `1` (default value), the result will have the same sign as this BigNumber,
|
||||
* and it will match that of Javascript's `%` operator (within the limits of double precision) and BigDecimal's `remainder` method.
|
||||
*/
|
||||
mod(n: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber negated, i.e. multiplied by `-1`.
|
||||
*/
|
||||
negated(): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber negated, i.e. multiplied by `-1`.
|
||||
*/
|
||||
neg(): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber plus `n`.
|
||||
*/
|
||||
plus(n: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber plus `n`.
|
||||
*/
|
||||
add(n: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns the number of significant digits of the value of this BigNumber.
|
||||
*
|
||||
* If `z` is `true` or `1` then any trailing zeros of the integer part of a number are counted as significant digits, otherwise they are not.
|
||||
*/
|
||||
precision(z?: boolean | 0 | 1): number;
|
||||
|
||||
/**
|
||||
* Returns the number of significant digits of the value of this BigNumber.
|
||||
*
|
||||
* If `z` is `true` or `1` then any trailing zeros of the integer part of a number are counted as significant digits, otherwise they are not.
|
||||
*/
|
||||
sd(z?: boolean | 0 | 1): number;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber rounded by rounding mode `rm` to a maximum of `dp` decimal places.
|
||||
*
|
||||
* If `dp` is omitted, or is `null` or `undefined`, the return value is `n` rounded to a whole number.
|
||||
*
|
||||
* If `rm` is omitted, or is `null` or `undefined`, `ROUNDING_MODE` is used.
|
||||
*/
|
||||
round(dp?: number, rm?: RoundingMode): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber shifted `n` places.
|
||||
*
|
||||
* The shift is of the decimal point, i.e. of powers of ten, and is to the left if `n` is negative or to the right if `n` is positive.
|
||||
*/
|
||||
shift(n: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the square root of the value of this BigNumber, rounded according to the current `DECIMAL_PLACES` and `ROUNDING_MODE` configuration.
|
||||
*
|
||||
* The return value will be correctly rounded, i.e. rounded as if the result was first calculated to an infinite number of correct digits before rounding.
|
||||
*/
|
||||
squareRoot(): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the square root of the value of this BigNumber, rounded according to the current `DECIMAL_PLACES` and `ROUNDING_MODE` configuration.
|
||||
*
|
||||
* The return value will be correctly rounded, i.e. rounded as if the result was first calculated to an infinite number of correct digits before rounding.
|
||||
*/
|
||||
sqrt(): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber times `n`.
|
||||
*/
|
||||
times(n: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber times `n`.
|
||||
*/
|
||||
mul(n: NumberLike, base?: number): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber rounded to `sd` significant digits using rounding mode `rm`.
|
||||
*
|
||||
* If `sd` is omitted or is `null` or `undefined`, the return value will not be rounded.
|
||||
*
|
||||
* If `rm` is omitted or is `null` or `undefined`, ROUNDING_MODE will be used.
|
||||
*/
|
||||
toDigits(sd?: number, rm?: RoundingMode): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a string representing the value of this BigNumber in exponential notation rounded using rounding mode `rm` to `dp` decimal places,
|
||||
* i.e with one digit before the decimal point and `dp` digits after it.
|
||||
*
|
||||
* If the value of this BigNumber in exponential notation has fewer than `dp` fraction digits, the return value will be appended with zeros accordingly.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* If `rm` is omitted or is `null` or `undefined`, `ROUNDING_MODE` is used.
|
||||
*/
|
||||
toExponential(dp?: number, rm?: RoundingMode): string;
|
||||
|
||||
/**
|
||||
* Returns a string representing the value of this BigNumber in normal (fixed-point) notation rounded to `dp` decimal places using rounding mode `rm`.
|
||||
*
|
||||
* If the value of this BigNumber in normal notation has fewer than `dp` fraction digits, the return value will be appended with zeros accordingly.
|
||||
*
|
||||
* Unlike `Number.prototype.toFixed`, which returns exponential notation if a number is greater or equal to `10e21`, this method will always return normal notation.
|
||||
*
|
||||
* If `dp` is omitted or is `null` or `undefined`, the return value will be unrounded and in normal notation.
|
||||
* This is also unlike `Number.prototype.toFixed`, which returns the value to zero decimal places.
|
||||
* It is useful when fixed-point notation is required and the current `EXPONENTIAL_AT` setting causes `toString` to return exponential notation.
|
||||
*
|
||||
* If `rm` is omitted or is `null` or `undefined`, `ROUNDING_MODE` is used.
|
||||
*/
|
||||
toFixed(dp?: number, rm?: RoundingMode): string;
|
||||
|
||||
/**
|
||||
* Returns a string representing the value of this BigNumber in normal (fixed-point) notation rounded to `dp` decimal places using rounding mode `rm`,
|
||||
* and formatted according to the properties of the `FORMAT` object.
|
||||
*
|
||||
* If `dp` is omitted or is `null` or `undefined`, then the return value is not rounded to a fixed number of decimal places.
|
||||
*
|
||||
* If `rm` is omitted or is `null` or `undefined`, `ROUNDING_MODE` is used.
|
||||
*/
|
||||
toFormat(dp?: number, rm?: RoundingMode): string;
|
||||
|
||||
/**
|
||||
* Returns a string array representing the value of this BigNumber as a simple fraction with an integer numerator and an integer denominator.
|
||||
* The denominator will be a positive non-zero value less than or equal to `max`.
|
||||
*
|
||||
* If a maximum denominator, `max`, is not specified, or is `null` or `undefined`, the denominator will be the lowest value necessary to represent the number exactly.
|
||||
*/
|
||||
toFraction(max?: NumberLike): [string, string];
|
||||
|
||||
/**
|
||||
* As `valueOf`.
|
||||
*/
|
||||
toJSON(): string;
|
||||
|
||||
/**
|
||||
* Returns the value of this BigNumber as a JavaScript number primitive.
|
||||
*
|
||||
* Type coercion with, for example, the unary plus operator will also work, except that a BigNumber with the value minus zero will be converted to positive zero.
|
||||
*/
|
||||
toNumber(): number;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber raised to the power `n`, and optionally modulo a modulus `m`.
|
||||
*
|
||||
* If `n` is negative the result is rounded according to the current `DECIMAL_PLACES` and `ROUNDING_MODE` configuration.
|
||||
*/
|
||||
toPower(n: number, m?: NumberLike): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber raised to the power `n`, and optionally modulo a modulus `m`.
|
||||
*
|
||||
* If `n` is negative the result is rounded according to the current `DECIMAL_PLACES` and `ROUNDING_MODE` configuration.
|
||||
*/
|
||||
pow(n: number, m?: NumberLike): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a string representing the value of this BigNumber rounded to `sd` significant digits using rounding mode `rm`.
|
||||
*
|
||||
* If `sd` is less than the number of digits necessary to represent the integer part of the value in normal (fixed-point) notation, then exponential notation is used.
|
||||
*
|
||||
* If `sd` is omitted, or is `null` or `undefined`, then the return value is the same as `n.toString()`.
|
||||
*
|
||||
* If `rm` is omitted or is `null` or `undefined`, `ROUNDING_MODE` is used.
|
||||
*/
|
||||
toPrecision(sd?: number, rm?: RoundingMode): string;
|
||||
|
||||
/**
|
||||
* Returns a string representing the value of this BigNumber in the specified base, or base `10` if `base` is omitted or is `null` or `undefined`.
|
||||
*/
|
||||
toString(base?: number): string;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber truncated to a whole number.
|
||||
*/
|
||||
truncated(): BigNumber;
|
||||
|
||||
/**
|
||||
* Returns a BigNumber whose value is the value of this BigNumber truncated to a whole number.
|
||||
*/
|
||||
trunc(): BigNumber;
|
||||
|
||||
/**
|
||||
* As `toString`, but does not accept a base argument and includes the minus sign for negative zero.
|
||||
*/
|
||||
valueOf(): string;
|
||||
|
||||
/**
|
||||
* coefficient
|
||||
* @description Array of base 1e14 numbers
|
||||
*/
|
||||
c: number[] | null;
|
||||
|
||||
/**
|
||||
* exponent
|
||||
* @description Integer, -1000000000 to 1000000000 inclusive
|
||||
*/
|
||||
e: number | null;
|
||||
|
||||
/**
|
||||
* sign
|
||||
*/
|
||||
s: -1 | 1 | null;
|
||||
|
||||
/**
|
||||
* type identifier
|
||||
*/
|
||||
isBigNumber: true;
|
||||
}
|
||||
}
|
||||
22
bignumber.js/tsconfig.json
Normal file
22
bignumber.js/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"bignumber.js-tests.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user