Interface: BigNumber
Properties
| Property | Type | Description |
|---|---|---|
c | number[] | Returns an array of single digits |
e | number | Returns the exponent, Integer, -1e+6 to 1e+6 inclusive |
s | number | Returns the sign, -1 or 1 |
Methods
abs()
abs(): Big;Returns a Big number whose value is the absolute value, i.e. the magnitude, of this Big number.
Returns
Big
add()
add(n: BigSource): Big;Returns a Big number whose value is the value of this Big number plus n - alias for .plus().
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
Big
Throws
NaN if n is invalid.
cmp()
cmp(n: BigSource): Comparison;Compare the values.
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
Comparison
Throws
NaN if n is invalid.
div()
div(n: BigSource): Big;Returns a Big number whose value is the value of this Big number divided by n.
If the result has more fraction digits than is specified by Big.DP, it will be rounded to Big.DP decimal places using rounding mode Big.RM.
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
Big
Throws
NaN if n is invalid.
Throws
±Infinity on division by zero.
Throws
NaN on division of zero by zero.
eq()
eq(n: BigSource): boolean;Returns true if the value of this Big equals the value of n, otherwise returns false.
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
boolean
Throws
NaN if n is invalid.
gt()
gt(n: BigSource): boolean;Returns true if the value of this Big is greater than the value of n, otherwise returns false.
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
boolean
Throws
NaN if n is invalid.
gte()
gte(n: BigSource): boolean;Returns true if the value of this Big is greater than or equal to the value of n, otherwise returns false.
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
boolean
Throws
NaN if n is invalid.
lt()
lt(n: BigSource): boolean;Returns true if the value of this Big is less than the value of n, otherwise returns false.
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
boolean
Throws
NaN if n is invalid.
lte()
lte(n: BigSource): boolean;Returns true if the value of this Big is less than or equal to the value of n, otherwise returns false.
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
boolean
Throws
NaN if n is invalid.
minus()
minus(n: BigSource): Big;Returns a Big number whose value is the value of this Big number minus n.
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
Big
Throws
NaN if n is invalid.
mod()
mod(n: BigSource): Big;Returns a Big number whose value is the value of this Big number modulo n, i.e. the integer remainder of dividing this Big number by n.
The result will have the same sign as this Big number, and it will match that of Javascript's % operator (within the limits of its precision) and BigDecimal's remainder method.
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
Big
Throws
NaN if n is negative or otherwise invalid.
mul()
mul(n: BigSource): Big;Returns a Big number whose value is the value of this Big number times n - alias for .times().
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
Big
Throws
NaN if n is invalid.
neg()
neg(): Big;Return a new Big whose value is the value of this Big negated.
Returns
Big
plus()
plus(n: BigSource): Big;Returns a Big number whose value is the value of this Big number plus n.
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
Big
Throws
NaN if n is invalid.
pow()
pow(exp: number): Big;Returns a Big number whose value is the value of this Big number raised to the power exp.
If exp is negative and the result has more fraction digits than is specified by Big.DP, it will be rounded to Big.DP decimal places using rounding mode Big.RM.
Parameters
| Parameter | Type | Description |
|---|---|---|
exp | number | The power to raise the number to, -1e+6 to 1e+6 inclusive |
Returns
Big
Throws
!pow! if exp is invalid.
Note: High value exponents may cause this method to be slow to return.
prec()
prec(sd: number, rm?: RoundingMode): Big;Return a new Big whose value is the value of this Big rounded to a maximum precision of sd significant digits using rounding mode rm, or Big.RM if rm is not specified.
Parameters
| Parameter | Type | Description |
|---|---|---|
sd | number | Significant digits: integer, 1 to MAX_DP inclusive. |
rm? | RoundingMode | Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up). |
Returns
Big
Throws
!prec! if sd is invalid.
Throws
!Big.RM! if rm is invalid.
round()
round(dp?: number, rm?: RoundingMode): Big;Returns a Big number whose value is the value of this Big number rounded using rounding mode rm to a maximum of dp decimal places.
Parameters
| Parameter | Type | Description |
|---|---|---|
dp? | number | Decimal places, 0 to 1e+6 inclusive |
rm? | RoundingMode | Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up). |
Returns
Big
Throws
!round! if dp is invalid.
Throws
!Big.RM! if rm is invalid.
sqrt()
sqrt(): Big;Returns a Big number whose value is the square root of this Big number.
If the result has more fraction digits than is specified by Big.DP, it will be rounded to Big.DP decimal places using rounding mode Big.RM.
Returns
Big
Throws
NaN if this Big number is negative.
sub()
sub(n: BigSource): Big;Returns a Big number whose value is the value of this Big number minus n - alias for .minus().
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
Big
Throws
NaN if n is invalid.
times()
times(n: BigSource): Big;Returns a Big number whose value is the value of this Big number times n.
Parameters
| Parameter | Type |
|---|---|
n | BigSource |
Returns
Big
Throws
NaN if n is invalid.
toExponential()
toExponential(dp?: number, rm?: RoundingMode): string;Returns a string representing the value of this Big number in exponential notation to a fixed number of decimal places dp.
If the value of this Big number in exponential notation has more digits to the right of the decimal point than is specified by dp, the return value will be rounded to dp decimal places using rounding mode Big.RM.
If the value of this Big number in exponential notation has fewer digits to the right of the decimal point than is specified by dp, 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.
Parameters
| Parameter | Type | Description |
|---|---|---|
dp? | number | Decimal places, 0 to 1e+6 inclusive |
rm? | RoundingMode | Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up). |
Returns
string
Throws
!toFix! if dp is invalid.
toFixed()
toFixed(dp?: number, rm?: RoundingMode): string;Returns a string representing the value of this Big number in normal notation to a fixed number of decimal places dp.
If the value of this Big number in normal notation has more digits to the right of the decimal point than is specified by dp, the return value will be rounded to dp decimal places using rounding mode Big.RM.
If the value of this Big number in normal notation has fewer fraction digits then is specified by dp, 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 1021, this method will always return normal notation.
If dp is omitted, or is null or undefined, then the return value is simply the value in normal notation. This is also unlike Number.prototype.toFixed, which returns the value to zero decimal places.
Parameters
| Parameter | Type | Description |
|---|---|---|
dp? | number | Decimal places, 0 to 1e+6 inclusive |
rm? | RoundingMode | Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up). |
Returns
string
Throws
!toFix! if dp is invalid.
toJSON()
toJSON(): string;Returns a string representing the value of this Big number.
If this Big number has a positive exponent that is equal to or greater than 21, or a negative exponent equal to or less than -7, then exponential notation is returned.
The point at which toString returns exponential rather than normal notation can be adjusted by changing the value of Big.E_POS and Big.E_NEG. By default, Big numbers correspond to Javascript's number type in this regard.
Returns
string
toNumber()
toNumber(): number;Returns a primitive number representing the value of this Big number.
If Big.strict is true an error will be thrown if toNumber is called on a Big number which cannot be converted to a primitive number without a loss of precision.
Returns
number
Since
6.0
toPrecision()
toPrecision(sd?: number, rm?: RoundingMode): string;Returns a string representing the value of this Big number to the specified number of significant digits sd.
If the value of this Big number has more digits than is specified by sd, the return value will be rounded to sd significant digits using rounding mode Big.RM.
If the value of this Big number has fewer digits than is specified by sd, the return value will be appended with zeros accordingly.
If sd is less than the number of digits necessary to represent the integer part of the value in normal notation, then exponential notation is used.
If sd is omitted, or is null or undefined, then the return value is the same as .toString().
Parameters
| Parameter | Type | Description |
|---|---|---|
sd? | number | Significant digits, 1 to 1e+6 inclusive |
rm? | RoundingMode | Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up). |
Returns
string
Throws
!toPre! if sd is invalid.
toString()
toString(): string;Returns a string representing the value of this Big number.
If this Big number has a positive exponent that is equal to or greater than 21, or a negative exponent equal to or less than -7, then exponential notation is returned.
The point at which toString returns exponential rather than normal notation can be adjusted by changing the value of Big.E_POS and Big.E_NEG. By default, Big numbers correspond to Javascript's number type in this regard.
Returns
string
valueOf()
valueOf(): string;Returns a string representing the value of this Big number.
If this Big number has a positive exponent that is equal to or greater than 21, or a negative exponent equal to or less than -7, then exponential notation is returned.
The point at which toString returns exponential rather than normal notation can be adjusted by changing the value of Big.E_POS and Big.E_NEG. By default, Big numbers correspond to Javascript's number type in this regard.
Returns
string