@types/big.js
- Version 6.2.2
- Published
- 18.5 kB
- No dependencies
- MIT license
Install
npm i @types/big.js
yarn add @types/big.js
pnpm add @types/big.js
Overview
TypeScript definitions for big.js
Index
Variables
Interfaces
Type Aliases
Variables
variable Big
const Big: Big.BigConstructor;
Interfaces
interface Big
interface Big {}
property c
c: number[];
Returns an array of single digits
property e
e: number;
Returns the exponent, Integer, -1e+6 to 1e+6 inclusive
property s
s: number;
Returns the sign, -1 or 1
method abs
abs: () => Big;
Returns a Big number whose value is the absolute value, i.e. the magnitude, of this Big number.
method add
add: (n: BigSource) => Big;
Returns a Big number whose value is the value of this Big number plus n - alias for .plus().
Throws
NaN
if n is invalid.
method cmp
cmp: (n: BigSource) => Comparison;
Compare the values.
Throws
NaN
if n is invalid.
method 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.
Throws
NaN
if n is invalid.Throws
±Infinity
on division by zero.Throws
NaN
on division of zero by zero.
method eq
eq: (n: BigSource) => boolean;
Returns true if the value of this Big equals the value of n, otherwise returns false.
Throws
NaN
if n is invalid.
method gt
gt: (n: BigSource) => boolean;
Returns true if the value of this Big is greater than the value of n, otherwise returns false.
Throws
NaN
if n is invalid.
method 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.
Throws
NaN
if n is invalid.
method lt
lt: (n: BigSource) => boolean;
Returns true if the value of this Big is less than the value of n, otherwise returns false.
Throws
NaN
if n is invalid.
method 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.
Throws
NaN
if n is invalid.
method minus
minus: (n: BigSource) => Big;
Returns a Big number whose value is the value of this Big number minus n.
Throws
NaN
if n is invalid.
method 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.
Throws
NaN
if n is negative or otherwise invalid.
method mul
mul: (n: BigSource) => Big;
Returns a Big number whose value is the value of this Big number times n - alias for .times().
Throws
NaN
if n is invalid.
method neg
neg: () => Big;
Return a new Big whose value is the value of this Big negated.
method plus
plus: (n: BigSource) => Big;
Returns a Big number whose value is the value of this Big number plus n.
Throws
NaN
if n is invalid.
method 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.
Parameter exp
The power to raise the number to, -1e+6 to 1e+6 inclusive
Throws
!pow!
if exp is invalid.Note: High value exponents may cause this method to be slow to return.
method 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.
Parameter sd
Significant digits: integer, 1 to MAX_DP inclusive.
Parameter rm
Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
Throws
!prec!
if sd is invalid.Throws
!Big.RM!
if rm is invalid.
method 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.
Parameter dp
Decimal places, 0 to 1e+6 inclusive
Parameter rm
Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
Throws
!round!
if dp is invalid.Throws
!Big.RM!
if rm is invalid.
method 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.
Throws
NaN
if this Big number is negative.
method sub
sub: (n: BigSource) => Big;
Returns a Big number whose value is the value of this Big number minus n - alias for .minus().
Throws
NaN
if n is invalid.
method times
times: (n: BigSource) => Big;
Returns a Big number whose value is the value of this Big number times n.
Throws
NaN
if n is invalid.
method 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.
Parameter dp
Decimal places, 0 to 1e+6 inclusive
Parameter rm
Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
Throws
!toFix!
if dp is invalid.
method 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.
Parameter dp
Decimal places, 0 to 1e+6 inclusive
Parameter rm
Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
Throws
!toFix!
if dp is invalid.
method 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.
method 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.
6.0
method 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().
Parameter sd
Significant digits, 1 to 1e+6 inclusive
Parameter rm
Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
Throws
!toPre!
if sd is invalid.
method 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.
method 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.
interface BigConstructor
interface BigConstructor {}
property Big
readonly Big: BigConstructor;
property DP
DP: number;
The maximum number of decimal places of the results of operations involving division. It is relevant only to the div and sqrt methods, and the pow method when the exponent is negative.
0 to 1e+6 inclusive Default value: 20
property NE
NE: number;
The negative exponent value at and below which toString returns exponential notation.
-1e+6 to 0 inclusive Default value: -7
property PE
PE: number;
The positive exponent value at and above which toString returns exponential notation.
0 to 1e+6 inclusive Default value: 21
property RM
RM: number;
The rounding mode used in the above operations and by round, toExponential, toFixed and toPrecision. Default value: 1
property roundDown
readonly roundDown: 0;
Rounds towards zero. I.e. truncate, no rounding.
property roundHalfEven
readonly roundHalfEven: 2;
Rounds towards nearest neighbour. If equidistant, rounds towards even neighbour.
property roundHalfUp
readonly roundHalfUp: 1;
Rounds towards nearest neighbour. If equidistant, rounds away from zero.
property roundUp
readonly roundUp: 3;
Rounds away from zero.
property strict
strict: boolean;
When set to true, an error will be thrown if a primitive number is passed to the Big constructor, or if valueOf is called, or if toNumber is called on a Big which cannot be converted to a primitive number without a loss of precision.
true|false Default value: false
construct signature
new (value: BigSource): Big;
Returns a new instance of a Big number object
String values may be in exponential, as well as normal (non-exponential) notation. There is no limit to the number of digits of a string value (other than that of Javascript's maximum array size), but the largest recommended exponent magnitude is 1e+6. Infinity, NaN and hexadecimal literal strings, e.g. '0xff', are not valid. String values in octal literal form will be interpreted as decimals, e.g. '011' is 11, not 9.
Throws
NaN
on an invalid value.
call signature
(value: BigSource): Big;
Returns a new instance of a Big number object
String values may be in exponential, as well as normal (non-exponential) notation. There is no limit to the number of digits of a string value (other than that of Javascript's maximum array size), but the largest recommended exponent magnitude is 1e+6. Infinity, NaN and hexadecimal literal strings, e.g. '0xff', are not valid. String values in octal literal form will be interpreted as decimals, e.g. '011' is 11, not 9.
Throws
NaN
on an invalid value.
call signature
(): BigConstructor;
Create an additional Big number constructor
Values created with the returned constructor will have a separate set of configuration values. This can be used to create Big objects with different DP and RM values. Big numbers created by different constructors can be used together in operations, and it is the DP and RM setting of the Big number that an operation is called upon that will apply. In the interest of memory efficiency, all Big number constructors share the same prototype object, so while the DP and RM (and any other own properties) of a constructor are isolated and untouchable by another, its prototype methods are not.
Type Aliases
type Big
type Big = Big.Big;
type BigSource
type BigSource = number | string | Big;
type Comparison
type Comparison = -1 | 0 | 1;
GT = 1, EQ = 0, LT = -1
type RoundingMode
type RoundingMode = 0 | 1 | 2 | 3;
RoundDown = 0, RoundHalfUp = 1, RoundHalfEven = 2, RoundUp = 3
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/big.js
.
- Markdown[](https://www.jsdocs.io/package/@types/big.js)
- HTML<a href="https://www.jsdocs.io/package/@types/big.js"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3166 ms. - Missing or incorrect documentation? Open an issue for this package.