Skip to main content
Module

x/math/mod.ts>Big

Deno module for high-precision calculations and scientific computing
Latest
interface Big
Re-export
import { type Big } from "https://deno.land/x/math@v1.1.0/mod.ts";

Properties

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(): Big

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

add(n: BigSource): Big

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

Compare the values.

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.

eq(n: BigSource): boolean

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

gt(n: BigSource): boolean

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

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.

lt(n: BigSource): boolean

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

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.

minus(n: BigSource): Big

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

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.

mul(n: BigSource): Big

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

plus(n: BigSource): Big

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

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.

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.

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.

sub(n: BigSource): Big

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

times(n: BigSource): Big

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

toExponential(dp?: number): 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.

toFixed(dp?: number): 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.

toPrecision(sd?: number): 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().

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.

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.

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.

variable Big
Re-export
import { Big } from "https://deno.land/x/math@v1.1.0/mod.ts";