Skip to content

Interface: Big

Properties

PropertyTypeDescription
cnumber[]Returns an array of single digits
enumberReturns the exponent, Integer, -1e+6 to 1e+6 inclusive
snumberReturns the sign, -1 or 1

Methods

abs()

ts
abs(): Big;

Returns a Big number whose value is the absolute value, i.e. the magnitude, of this Big number.

Returns

Big


add()

ts
add(n: BigSource): Big;

Returns a Big number whose value is the value of this Big number plus n - alias for .plus().

Parameters

ParameterType
nBigSource

Returns

Big

Throws

NaN if n is invalid.


cmp()

ts
cmp(n: BigSource): Comparison;

Compare the values.

Parameters

ParameterType
nBigSource

Returns

Comparison

Throws

NaN if n is invalid.


div()

ts
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

ParameterType
nBigSource

Returns

Big

Throws

NaN if n is invalid.

Throws

±Infinity on division by zero.

Throws

NaN on division of zero by zero.


eq()

ts
eq(n: BigSource): boolean;

Returns true if the value of this Big equals the value of n, otherwise returns false.

Parameters

ParameterType
nBigSource

Returns

boolean

Throws

NaN if n is invalid.


gt()

ts
gt(n: BigSource): boolean;

Returns true if the value of this Big is greater than the value of n, otherwise returns false.

Parameters

ParameterType
nBigSource

Returns

boolean

Throws

NaN if n is invalid.


gte()

ts
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

ParameterType
nBigSource

Returns

boolean

Throws

NaN if n is invalid.


lt()

ts
lt(n: BigSource): boolean;

Returns true if the value of this Big is less than the value of n, otherwise returns false.

Parameters

ParameterType
nBigSource

Returns

boolean

Throws

NaN if n is invalid.


lte()

ts
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

ParameterType
nBigSource

Returns

boolean

Throws

NaN if n is invalid.


minus()

ts
minus(n: BigSource): Big;

Returns a Big number whose value is the value of this Big number minus n.

Parameters

ParameterType
nBigSource

Returns

Big

Throws

NaN if n is invalid.


mod()

ts
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

ParameterType
nBigSource

Returns

Big

Throws

NaN if n is negative or otherwise invalid.


mul()

ts
mul(n: BigSource): Big;

Returns a Big number whose value is the value of this Big number times n - alias for .times().

Parameters

ParameterType
nBigSource

Returns

Big

Throws

NaN if n is invalid.


neg()

ts
neg(): Big;

Return a new Big whose value is the value of this Big negated.

Returns

Big


plus()

ts
plus(n: BigSource): Big;

Returns a Big number whose value is the value of this Big number plus n.

Parameters

ParameterType
nBigSource

Returns

Big

Throws

NaN if n is invalid.


pow()

ts
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

ParameterTypeDescription
expnumberThe 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()

ts
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

ParameterTypeDescription
sdnumberSignificant digits: integer, 1 to MAX_DP inclusive.
rm?RoundingModeRounding 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()

ts
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

ParameterTypeDescription
dp?numberDecimal places, 0 to 1e+6 inclusive
rm?RoundingModeRounding 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()

ts
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()

ts
sub(n: BigSource): Big;

Returns a Big number whose value is the value of this Big number minus n - alias for .minus().

Parameters

ParameterType
nBigSource

Returns

Big

Throws

NaN if n is invalid.


times()

ts
times(n: BigSource): Big;

Returns a Big number whose value is the value of this Big number times n.

Parameters

ParameterType
nBigSource

Returns

Big

Throws

NaN if n is invalid.


toExponential()

ts
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

ParameterTypeDescription
dp?numberDecimal places, 0 to 1e+6 inclusive
rm?RoundingModeRounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).

Returns

string

Throws

!toFix! if dp is invalid.


toFixed()

ts
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

ParameterTypeDescription
dp?numberDecimal places, 0 to 1e+6 inclusive
rm?RoundingModeRounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).

Returns

string

Throws

!toFix! if dp is invalid.


toJSON()

ts
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()

ts
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()

ts
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

ParameterTypeDescription
sd?numberSignificant digits, 1 to 1e+6 inclusive
rm?RoundingModeRounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).

Returns

string

Throws

!toPre! if sd is invalid.


toString()

ts
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()

ts
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