From 6df248f559c984de7975927055b7e0aa3e2b1079 Mon Sep 17 00:00:00 2001 From: Michael Mclaughlin Date: Thu, 23 Jan 2025 15:17:36 +0000 Subject: [PATCH] #181 Support BigInt --- decimal.js | 159 ++++++++++++++++++++++++++++----------------------- doc/API.html | 142 ++++++++++++++++++++++----------------------- 2 files changed, 158 insertions(+), 143 deletions(-) diff --git a/decimal.js b/decimal.js index 13fe9ef..c3ac7c5 100644 --- a/decimal.js +++ b/decimal.js @@ -218,8 +218,8 @@ * Return a new Decimal whose value is the value of this Decimal clamped to the range * delineated by `min` and `max`. * - * min {number|string|Decimal} - * max {number|string|Decimal} + * min {number|string|bigInt|Decimal} + * max {number|string|bigInt|Decimal} * */ P.clampedTo = P.clamp = function (min, max) { @@ -1124,7 +1124,7 @@ * log[b](Infinity) = Infinity * log[b](NaN) = NaN * - * [base] {number|string|Decimal} The base of the logarithm. + * [base] {number|string|bigInt|Decimal} The base of the logarithm. * */ P.logarithm = P.log = function (base) { @@ -1218,7 +1218,7 @@ /* * Return a new Decimal whose value is the maximum of the arguments and the value of this Decimal. * - * arguments {number|string|Decimal} + * arguments {number|string|bigInt|Decimal} * P.max = function () { Array.prototype.push.call(arguments, this); @@ -1230,7 +1230,7 @@ /* * Return a new Decimal whose value is the minimum of the arguments and the value of this Decimal. * - * arguments {number|string|Decimal} + * arguments {number|string|bigInt|Decimal} * P.min = function () { Array.prototype.push.call(arguments, this); @@ -2053,7 +2053,7 @@ * denominator. If a maximum denominator is not specified, the denominator will be the lowest * value necessary to represent the number exactly. * - * [maxD] {number|string|Decimal} Maximum denominator. Integer >= 1 and < Infinity. + * [maxD] {number|string|bigInt|Decimal} Maximum denominator. Integer >= 1 and < Infinity. * */ P.toFraction = function (maxD) { @@ -2141,7 +2141,7 @@ * * The return value is not affected by the value of `precision`. * - * y {number|string|Decimal} The magnitude to round to a multiple of. + * y {number|string|bigInt|Decimal} The magnitude to round to a multiple of. * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive. * * 'toNearest() rounding mode not an integer: {rm}' @@ -2261,7 +2261,7 @@ * * If a result is incorrectly rounded the maximum error will be 1 ulp (unit in last place). * - * y {number|string|Decimal} The power to which to raise this Decimal. + * y {number|string|bigInt|Decimal} The power to which to raise this Decimal. * */ P.toPower = P.pow = function (y) { @@ -3254,15 +3254,15 @@ for (; ++i < args.length;) { y = new Ctor(args[i]); - + // NaN? if (!y.s) { x = y; break; } - + k = x.cmp(y); - + if (k === n || k === 0 && x.s === n) { x = y; } @@ -3522,6 +3522,8 @@ function parseDecimal(x, str) { var e, i, len; + // TODO BigInt str: no need to check for decimal point, exponential form or leading zeros. + // Decimal point? if ((e = str.indexOf('.')) > -1) str = str.replace('.', ''); @@ -3989,7 +3991,7 @@ /* * Return a new Decimal whose value is the absolute value of `x`. * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function abs(x) { @@ -4000,7 +4002,7 @@ /* * Return a new Decimal whose value is the arccosine in radians of `x`. * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function acos(x) { @@ -4012,7 +4014,7 @@ * Return a new Decimal whose value is the inverse of the hyperbolic cosine of `x`, rounded to * `precision` significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} A value in radians. + * x {number|string|bigInt|Decimal} A value in radians. * */ function acosh(x) { @@ -4024,8 +4026,8 @@ * Return a new Decimal whose value is the sum of `x` and `y`, rounded to `precision` significant * digits using rounding mode `rounding`. * - * x {number|string|Decimal} - * y {number|string|Decimal} + * x {number|string|bigInt|Decimal} + * y {number|string|bigInt|Decimal} * */ function add(x, y) { @@ -4037,7 +4039,7 @@ * Return a new Decimal whose value is the arcsine in radians of `x`, rounded to `precision` * significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function asin(x) { @@ -4049,7 +4051,7 @@ * Return a new Decimal whose value is the inverse of the hyperbolic sine of `x`, rounded to * `precision` significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} A value in radians. + * x {number|string|bigInt|Decimal} A value in radians. * */ function asinh(x) { @@ -4061,7 +4063,7 @@ * Return a new Decimal whose value is the arctangent in radians of `x`, rounded to `precision` * significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function atan(x) { @@ -4073,7 +4075,7 @@ * Return a new Decimal whose value is the inverse of the hyperbolic tangent of `x`, rounded to * `precision` significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} A value in radians. + * x {number|string|bigInt|Decimal} A value in radians. * */ function atanh(x) { @@ -4088,8 +4090,8 @@ * Domain: [-Infinity, Infinity] * Range: [-pi, pi] * - * y {number|string|Decimal} The y-coordinate. - * x {number|string|Decimal} The x-coordinate. + * y {number|string|bigInt|Decimal} The y-coordinate. + * x {number|string|bigInt|Decimal} The x-coordinate. * * atan2(±0, -0) = ±pi * atan2(±0, +0) = ±0 @@ -4154,7 +4156,7 @@ * Return a new Decimal whose value is the cube root of `x`, rounded to `precision` significant * digits using rounding mode `rounding`. * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function cbrt(x) { @@ -4165,7 +4167,7 @@ /* * Return a new Decimal whose value is `x` rounded to an integer using `ROUND_CEIL`. * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function ceil(x) { @@ -4176,9 +4178,9 @@ /* * Return a new Decimal whose value is `x` clamped to the range delineated by `min` and `max`. * - * x {number|string|Decimal} - * min {number|string|Decimal} - * max {number|string|Decimal} + * x {number|string|bigInt|Decimal} + * min {number|string|bigInt|Decimal} + * max {number|string|bigInt|Decimal} * */ function clamp(x, min, max) { @@ -4252,7 +4254,7 @@ * Return a new Decimal whose value is the cosine of `x`, rounded to `precision` significant * digits using rounding mode `rounding`. * - * x {number|string|Decimal} A value in radians. + * x {number|string|bigInt|Decimal} A value in radians. * */ function cos(x) { @@ -4264,7 +4266,7 @@ * Return a new Decimal whose value is the hyperbolic cosine of `x`, rounded to precision * significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} A value in radians. + * x {number|string|bigInt|Decimal} A value in radians. * */ function cosh(x) { @@ -4284,7 +4286,7 @@ * The Decimal constructor and exported function. * Return a new Decimal instance. * - * v {number|string|Decimal} A numeric value. + * v {number|string|bigInt|Decimal} A numeric value. * */ function Decimal(v) { @@ -4362,9 +4364,10 @@ } return; + } - // Infinity, NaN. - } else if (v * 0 !== 0) { + // Infinity or NaN? + if (v * 0 !== 0) { if (!v) x.s = NaN; x.e = NaN; x.d = null; @@ -4372,22 +4375,32 @@ } return parseDecimal(x, v.toString()); - - } else if (t !== 'string') { - throw Error(invalidArgument + v); } - // Minus sign? - if ((i = v.charCodeAt(0)) === 45) { - v = v.slice(1); - x.s = -1; - } else { - // Plus sign? - if (i === 43) v = v.slice(1); - x.s = 1; + if (t === 'string') { + if ((i = v.charCodeAt(0)) === 45) { // minus sign + v = v.slice(1); + x.s = -1; + } else { + if (i === 43) v = v.slice(1); // plus sign + x.s = 1; + } + + return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v); } - return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v); + if (t === 'bigint') { + if (v < 0) { + v = -v; + x.s = -1; + } else { + x.s = 1; + } + + return parseDecimal(x, v.toString()); + } + + throw Error(invalidArgument + v); } Decimal.prototype = P; @@ -4464,8 +4477,8 @@ * Return a new Decimal whose value is `x` divided by `y`, rounded to `precision` significant * digits using rounding mode `rounding`. * - * x {number|string|Decimal} - * y {number|string|Decimal} + * x {number|string|bigInt|Decimal} + * y {number|string|bigInt|Decimal} * */ function div(x, y) { @@ -4477,7 +4490,7 @@ * Return a new Decimal whose value is the natural exponential of `x`, rounded to `precision` * significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} The power to which to raise the base of the natural log. + * x {number|string|bigInt|Decimal} The power to which to raise the base of the natural log. * */ function exp(x) { @@ -4488,7 +4501,7 @@ /* * Return a new Decimal whose value is `x` round to an integer using `ROUND_FLOOR`. * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function floor(x) { @@ -4502,7 +4515,7 @@ * * hypot(a, b, ...) = sqrt(a^2 + b^2 + ...) * - * arguments {number|string|Decimal} + * arguments {number|string|bigInt|Decimal} * */ function hypot() { @@ -4544,7 +4557,7 @@ * Return a new Decimal whose value is the natural logarithm of `x`, rounded to `precision` * significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function ln(x) { @@ -4558,8 +4571,8 @@ * * log[y](x) * - * x {number|string|Decimal} The argument of the logarithm. - * y {number|string|Decimal} The base of the logarithm. + * x {number|string|bigInt|Decimal} The argument of the logarithm. + * y {number|string|bigInt|Decimal} The base of the logarithm. * */ function log(x, y) { @@ -4571,7 +4584,7 @@ * Return a new Decimal whose value is the base 2 logarithm of `x`, rounded to `precision` * significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function log2(x) { @@ -4583,7 +4596,7 @@ * Return a new Decimal whose value is the base 10 logarithm of `x`, rounded to `precision` * significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function log10(x) { @@ -4594,7 +4607,7 @@ /* * Return a new Decimal whose value is the maximum of the arguments. * - * arguments {number|string|Decimal} + * arguments {number|string|bigInt|Decimal} * */ function max() { @@ -4605,7 +4618,7 @@ /* * Return a new Decimal whose value is the minimum of the arguments. * - * arguments {number|string|Decimal} + * arguments {number|string|bigInt|Decimal} * */ function min() { @@ -4617,8 +4630,8 @@ * Return a new Decimal whose value is `x` modulo `y`, rounded to `precision` significant digits * using rounding mode `rounding`. * - * x {number|string|Decimal} - * y {number|string|Decimal} + * x {number|string|bigInt|Decimal} + * y {number|string|bigInt|Decimal} * */ function mod(x, y) { @@ -4630,8 +4643,8 @@ * Return a new Decimal whose value is `x` multiplied by `y`, rounded to `precision` significant * digits using rounding mode `rounding`. * - * x {number|string|Decimal} - * y {number|string|Decimal} + * x {number|string|bigInt|Decimal} + * y {number|string|bigInt|Decimal} * */ function mul(x, y) { @@ -4643,8 +4656,8 @@ * Return a new Decimal whose value is `x` raised to the power `y`, rounded to precision * significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} The base. - * y {number|string|Decimal} The exponent. + * x {number|string|bigInt|Decimal} The base. + * y {number|string|bigInt|Decimal} The exponent. * */ function pow(x, y) { @@ -4762,7 +4775,7 @@ * * To emulate `Math.round`, set rounding to 7 (ROUND_HALF_CEIL). * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function round(x) { @@ -4778,7 +4791,7 @@ * -0 if x is -0, * NaN otherwise * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function sign(x) { @@ -4791,7 +4804,7 @@ * Return a new Decimal whose value is the sine of `x`, rounded to `precision` significant digits * using rounding mode `rounding`. * - * x {number|string|Decimal} A value in radians. + * x {number|string|bigInt|Decimal} A value in radians. * */ function sin(x) { @@ -4803,7 +4816,7 @@ * Return a new Decimal whose value is the hyperbolic sine of `x`, rounded to `precision` * significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} A value in radians. + * x {number|string|bigInt|Decimal} A value in radians. * */ function sinh(x) { @@ -4815,7 +4828,7 @@ * Return a new Decimal whose value is the square root of `x`, rounded to `precision` significant * digits using rounding mode `rounding`. * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function sqrt(x) { @@ -4827,8 +4840,8 @@ * Return a new Decimal whose value is `x` minus `y`, rounded to `precision` significant digits * using rounding mode `rounding`. * - * x {number|string|Decimal} - * y {number|string|Decimal} + * x {number|string|bigInt|Decimal} + * y {number|string|bigInt|Decimal} * */ function sub(x, y) { @@ -4842,7 +4855,7 @@ * * Only the result is rounded, not the intermediate calculations. * - * arguments {number|string|Decimal} + * arguments {number|string|bigInt|Decimal} * */ function sum() { @@ -4862,7 +4875,7 @@ * Return a new Decimal whose value is the tangent of `x`, rounded to `precision` significant * digits using rounding mode `rounding`. * - * x {number|string|Decimal} A value in radians. + * x {number|string|bigInt|Decimal} A value in radians. * */ function tan(x) { @@ -4874,7 +4887,7 @@ * Return a new Decimal whose value is the hyperbolic tangent of `x`, rounded to `precision` * significant digits using rounding mode `rounding`. * - * x {number|string|Decimal} A value in radians. + * x {number|string|bigInt|Decimal} A value in radians. * */ function tanh(x) { @@ -4885,7 +4898,7 @@ /* * Return a new Decimal whose value is `x` truncated to an integer. * - * x {number|string|Decimal} + * x {number|string|bigInt|Decimal} * */ function trunc(x) { diff --git a/doc/API.html b/doc/API.html index 0460279..e11f004 100644 --- a/doc/API.html +++ b/doc/API.html @@ -254,7 +254,7 @@ li span{float:right;margin-right:10px;color:#c0c0c0} DecimalDecimal(value) ⇒ Decimal
-
value: number|string|Decimal
+
value: number|string|bigInt|Decimal
A legitimate value is an integer or float, including ±0, or is ±Infinity, or NaN. @@ -312,7 +312,9 @@ new Decimal('0x0.0c') // '0.046875' new Decimal('0b1.1p-5') // '0.046875' new Decimal('0o1.4p-5') // '0.046875' -new Decimal('0x1.8p-5') // '0.046875' + +new Decimal(123456000n) // '123456000' +new Decimal(BigInt('-1')) // '-1' @@ -322,7 +324,7 @@ new Decimal('0x1.8p-5') // '0.046875'
abs.abs(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See absoluteValue.

a = Decimal.abs(x)
 b = new Decimal(x).abs()
@@ -331,7 +333,7 @@ a.equals(b)                    // true
acos.acos(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See inverseCosine.

a = Decimal.acos(x)
 b = new Decimal(x).acos()
@@ -340,7 +342,7 @@ a.equals(b)                    // true
acosh.acosh(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See inverseHyperbolicCosine.

a = Decimal.acosh(x)
 b = new Decimal(x).acosh()
@@ -350,8 +352,8 @@ a.equals(b)                    // true
add.add(x, y) ⇒ Decimal

- x: number|string|Decimal
- y: number|string|Decimal + x: number|string|bigInt|Decimal
+ y: number|string|bigInt|Decimal

See plus.

a = Decimal.add(x, y)
@@ -361,7 +363,7 @@ a.equals(b)                    // true
asin.asin(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See inverseSine.

a = Decimal.asin(x)
 b = new Decimal(x).asin()
@@ -370,7 +372,7 @@ a.equals(b)                    // true
asinh.asinh(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See inverseHyperbolicSine.

a = Decimal.asinh(x)
 b = new Decimal(x).asinh()
@@ -379,7 +381,7 @@ a.equals(b)                    // true
atan.atan(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See inverseTangent.

a = Decimal.atan(x)
 b = new Decimal(x).atan()
@@ -388,7 +390,7 @@ a.equals(b)                    // true
atanh.atanh(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See inverseHyperbolicTangent.

a = Decimal.atanh(x)
 b = new Decimal(x).atanh()
@@ -398,8 +400,8 @@ a.equals(b)                    // true
atan2.atan2(y, x) ⇒ Decimal

- y: number|string|Decimal
- x: number|string|Decimal + y: number|string|bigInt|Decimal
+ x: number|string|bigInt|Decimal

Returns a new Decimal whose value is the inverse tangent in radians of the quotient of @@ -423,7 +425,7 @@ a.equals(b) // true

cbrt.cbrt(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See cubeRoot.

a = Decimal.cbrt(x)
 b = new Decimal(x).cbrt()
@@ -432,7 +434,7 @@ a.equals(b)                    // true
ceil.ceil(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See ceil.

a = Decimal.ceil(x)
 b = new Decimal(x).ceil()
@@ -442,8 +444,8 @@ a.equals(b)                    // true
clamp.clamp(min, max) ⇒ Decimal

- min: number|string|Decimal
- max: number|string|Decimal + min: number|string|bigInt|Decimal
+ max: number|string|bigInt|Decimal

See clampedTo.

Decimal.clamp(10.1, 0, 10)     // '10'
@@ -488,7 +490,7 @@ D2 = Decimal.clone({ defaults: true, precision: 50 })
cos.cos(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See cosine.

a = Decimal.cos(x)
 b = new Decimal(x).cos()
@@ -497,7 +499,7 @@ a.equals(b)                    // true
cosh.cosh(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See hyperbolicCosine.

a = Decimal.cosh(x)
 b = new Decimal(x).cosh()
@@ -507,8 +509,8 @@ a.equals(b)                    // true
div.div(x, y) ⇒ Decimal

- x: number|string|Decimal
- y: number|string|Decimal + x: number|string|bigInt|Decimal
+ y: number|string|bigInt|Decimal

See dividedBy.

a = Decimal.div(x, y)
@@ -518,7 +520,7 @@ a.equals(b)                    // true
exp.exp(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See naturalExponential.

a = Decimal.exp(x)
 b = new Decimal(x).exp()
@@ -527,7 +529,7 @@ a.equals(b)                    // true
floor.floor(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See floor.

a = Decimal.floor(x)
 b = new Decimal(x).floor()
@@ -539,8 +541,8 @@ a.equals(b)                    // true
hypot.hypot([x [, y, ...]]) ⇒ Decimal

- x: number|string|Decimal
- y: number|string|Decimal + x: number|string|bigInt|Decimal
+ y: number|string|bigInt|Decimal

Returns a new Decimal whose value is the square root of the sum of the squares of the @@ -552,7 +554,7 @@ a.equals(b) // true

ln.ln(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See naturalLogarithm.

a = Decimal.ln(x)
 b = new Decimal(x).ln()
@@ -578,8 +580,8 @@ Decimal.isDecimal(b)           // false
log.log(x [, base]) ⇒ Decimal

- x: number|string|Decimal
- base: number|string|Decimal + x: number|string|bigInt|Decimal
+ base: number|string|bigInt|Decimal

See logarithm.

@@ -593,7 +595,7 @@ a.equals(b) // true

log2.log2(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns a new Decimal whose value is the base 2 logarithm of x, rounded to precision significant digits using rounding @@ -604,7 +606,7 @@ a.equals(b) // true

log10.log10(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns a new Decimal whose value is the base 10 logarithm of x, rounded to precision significant digits using rounding @@ -618,8 +620,8 @@ a.equals(b) // true max.max(x [, y, ...]) ⇒ Decimal

- x: number|string|Decimal
- y: number|string|Decimal + x: number|string|bigInt|Decimal
+ y: number|string|bigInt|Decimal

Returns a new Decimal whose value is the maximum of the arguments.

r = Decimal.max(x, y, z)
@@ -630,8 +632,8 @@ a.equals(b) // true min.min(x [, y, ...]) ⇒ Decimal

- x: number|string|Decimal
- y: number|string|Decimal + x: number|string|bigInt|Decimal
+ y: number|string|bigInt|Decimal

Returns a new Decimal whose value is the minimum of the arguments.

r = Decimal.min(x, y, z)
@@ -640,8 +642,8 @@ a.equals(b) // true
mod.mod(x, y) ⇒ Decimal

- x: number|string|Decimal
- y: number|string|Decimal + x: number|string|bigInt|Decimal
+ y: number|string|bigInt|Decimal

See modulo.

a = Decimal.mod(x, y)
@@ -652,8 +654,8 @@ a.equals(b)                    // true
mul.mul(x, y) ⇒ Decimal

- x: number|string|Decimal
- y: number|string|Decimal + x: number|string|bigInt|Decimal
+ y: number|string|bigInt|Decimal

See times.

a = Decimal.mul(x, y)
@@ -685,8 +687,8 @@ a.equals(b)                    // true
pow.pow(base, exponent) ⇒ Decimal

- base: number|string|Decimal
- exponent: number|string|Decimal + base: number|string|bigInt|Decimal
+ exponent: number|string|bigInt|Decimal

See toPower.

a = Decimal.pow(x, y)
@@ -735,7 +737,7 @@ Decimal.random(20)                  // '0.78193327636914089009'
round.round(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See round.

a = Decimal.round(x)
 b = new Decimal(x).round()
@@ -792,7 +794,7 @@ Decimal.set({ precision: 50, defaults: true })
sign.sign(x) ⇒ number
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

@@ -821,7 +823,7 @@ Decimal.set({ precision: 50, defaults: true })
sin.sin(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See sine.

a = Decimal.sin(x)
 b = new Decimal(x).sin()
@@ -830,7 +832,7 @@ a.equals(b)                    // true
sinh.sinh(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See hyperbolicSine.

a = Decimal.sinh(x)
 b = new Decimal(x).sinh()
@@ -839,7 +841,7 @@ a.equals(b)                    // true
sqrt.sqrt(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See squareRoot.

a = Decimal.sqrt(x)
 b = new Decimal(x).sqrt()
@@ -849,8 +851,8 @@ a.equals(b)                    // true
sub.sub(x, y) ⇒ Decimal

- x: number|string|Decimal
- y: number|string|Decimal + x: number|string|bigInt|Decimal
+ y: number|string|bigInt|Decimal

See minus.

a = Decimal.sub(x, y)
@@ -861,8 +863,8 @@ a.equals(b)                    // true
sum.sum(x [, y, ...]) ⇒ Decimal

- x: number|string|Decimal
- y: number|string|Decimal + x: number|string|bigInt|Decimal
+ y: number|string|bigInt|Decimal

Returns a new Decimal whose value is the sum of the arguments, @@ -879,7 +881,7 @@ Decimal.sum(x, y, z) // '10'

tan.tan(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See tangent.

a = Decimal.tan(x)
 b = new Decimal(x).tan()
@@ -888,7 +890,7 @@ a.equals(b)                    // true
tanh.tanh(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See hyperbolicTangent.

a = Decimal.tanh(x)
 b = new Decimal(x).tanh()
@@ -897,7 +899,7 @@ a.equals(b)                    // true
trunc.trunc(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

See truncated.

a = Decimal.trunc(x)
 b = new Decimal(x).trunc()
@@ -1282,8 +1284,8 @@ y.ceil()                      // '-1'
clampedTo.clamp(min, max) ⇒ Decimal

- min: number|string|Decimal
- max: number|string|Decimal + min: number|string|bigInt|Decimal
+ max: number|string|bigInt|Decimal

Returns a new Decimal whose value is the value of this Decimal clamped to the range @@ -1303,7 +1305,7 @@ x.clamp(-10, -0.1) // '-0.1'

comparedTo.cmp(x) ⇒ number
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns 
@@ -1383,7 +1385,7 @@ y.dp() // '6'
dividedBy.div(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns a new Decimal whose value is the value of this Decimal divided by x, rounded to precision significant digits using rounding @@ -1400,7 +1402,7 @@ x.div(5) // '71'

dividedToIntegerBy.divToInt(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Return a new Decimal whose value is the integer part of dividing this Decimal by x, rounded to precision significant digits @@ -1415,7 +1417,7 @@ x.divToInt(0.7) // '7'

equals.eq(x) ⇒ boolean
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns true if the value of this Decimal equals the value of x, otherwise returns false.
As with JavaScript, NaN does not @@ -1451,7 +1453,7 @@ y.floor() // '-2'

greaterThan.gt(x) ⇒ boolean
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns true if the value of this Decimal is greater than the value of x, otherwise returns false. @@ -1468,7 +1470,7 @@ new Decimal(0).gt(x) // false

greaterThanOrEqualTo.gte(x) ⇒ boolean
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns true if the value of this Decimal is greater than or equal to the value of x, otherwise returns false. @@ -1748,7 +1750,7 @@ y.isZero() // false

lessThan.lt(x) ⇒ boolean
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns true if the value of this Decimal is less than the value of x, otherwise returns false. @@ -1763,7 +1765,7 @@ new Decimal(0).lt(x) // true

lessThanOrEqualTo.lte(x) ⇒ boolean
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns true if the value of this Decimal is less than or equal to the value of x, otherwise returns false. @@ -1778,7 +1780,7 @@ new Decimal(-1).lte(x) // true

logarithm.log(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns a new Decimal whose value is the base x logarithm of the value of this Decimal, rounded to precision significant digits using @@ -1810,7 +1812,7 @@ y.log(2) // '8'

minus.minus(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns a new Decimal whose value is the value of this Decimal minus x, rounded to precision significant digits using rounding mode @@ -1824,7 +1826,7 @@ x.minus(0.1) // '0.2'

modulo.mod(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns a new Decimal whose value is the value of this Decimal modulo x, rounded to precision significant digits using rounding @@ -1931,7 +1933,7 @@ y.neg() // '1.3'

plus.plus(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns a new Decimal whose value is the value of this Decimal plus x, rounded to precision significant digits using rounding mode @@ -2042,7 +2044,7 @@ y.tan() // '0.93159645994407246117'

times.times(x) ⇒ Decimal
-

x: number|string|Decimal

+

x: number|string|bigInt|Decimal

Returns a new Decimal whose value is the value of this Decimal times x, rounded to precision significant digits using rounding @@ -2209,7 +2211,7 @@ y.toFixed(5) // '3.45600' .toFraction([max_denominator]) ⇒ [Decimal, Decimal]

- max_denominator: number|string|Decimal: 1 >= integer < + max_denominator: number|string|bigInt|Decimal: 1 >= integer < Infinity

@@ -2275,7 +2277,7 @@ x.toHex(1) // '0x1p+8' toNearest.toNearest(x [, rm]) ⇒ Decimal

- x: number|string|Decimal
+ x: number|string|bigInt|Decimal
rm: number: integer, 0 to 8 inclusive

@@ -2353,7 +2355,7 @@ x.toOctal(1) // '0o1p+8'

toPower.pow(x) ⇒ Decimal
-

x: number|string|Decimal: integer or non-integer

+

x: number|string|bigInt|Decimal: integer or non-integer

Returns a new Decimal whose value is the value of this Decimal raised to the power x, rounded to precision significant digits

Returns