1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2026-09-24 12:54:47 +00:00

Update decimal.mjs with decimal.js changes

This commit is contained in:
Michael Mclaughlin
2025-01-23 17:21:22 +00:00
parent b95c6eb3c7
commit 9817dd122c
4 changed files with 166 additions and 143 deletions

View File

@@ -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|bigInt|Decimal}
* max {number|string|bigInt|Decimal}
* min {number|string|bigint|Decimal}
* max {number|string|bigint|Decimal}
*
*/
P.clampedTo = P.clamp = function (min, max) {
@@ -723,8 +723,7 @@
*
*/
P.inverseCosine = P.acos = function () {
var halfPi,
x = this,
var x = this,
Ctor = x.constructor,
k = x.abs().cmp(1),
pr = Ctor.precision,
@@ -744,8 +743,9 @@
Ctor.precision = pr + 6;
Ctor.rounding = 1;
x = (new Ctor(1)).minus(x).div(x.plus(1)).sqrt().atan();
// See https://github.com/MikeMcl/decimal.js/pull/217
x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
Ctor.precision = pr;
Ctor.rounding = rm;
@@ -1124,7 +1124,7 @@
* log[b](Infinity) = Infinity
* log[b](NaN) = NaN
*
* [base] {number|string|bigInt|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|bigInt|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|bigInt|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|bigInt|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|bigInt|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|bigInt|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) {
@@ -3991,7 +3991,7 @@
/*
* Return a new Decimal whose value is the absolute value of `x`.
*
* x {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function abs(x) {
@@ -4002,7 +4002,7 @@
/*
* Return a new Decimal whose value is the arccosine in radians of `x`.
*
* x {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function acos(x) {
@@ -4014,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|bigInt|Decimal} A value in radians.
* x {number|string|bigint|Decimal} A value in radians.
*
*/
function acosh(x) {
@@ -4026,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|bigInt|Decimal}
* y {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
* y {number|string|bigint|Decimal}
*
*/
function add(x, y) {
@@ -4039,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|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function asin(x) {
@@ -4051,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|bigInt|Decimal} A value in radians.
* x {number|string|bigint|Decimal} A value in radians.
*
*/
function asinh(x) {
@@ -4063,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|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function atan(x) {
@@ -4075,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|bigInt|Decimal} A value in radians.
* x {number|string|bigint|Decimal} A value in radians.
*
*/
function atanh(x) {
@@ -4090,8 +4090,8 @@
* Domain: [-Infinity, Infinity]
* Range: [-pi, pi]
*
* y {number|string|bigInt|Decimal} The y-coordinate.
* x {number|string|bigInt|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
@@ -4156,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|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function cbrt(x) {
@@ -4167,7 +4167,7 @@
/*
* Return a new Decimal whose value is `x` rounded to an integer using `ROUND_CEIL`.
*
* x {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function ceil(x) {
@@ -4178,9 +4178,9 @@
/*
* Return a new Decimal whose value is `x` clamped to the range delineated by `min` and `max`.
*
* x {number|string|bigInt|Decimal}
* min {number|string|bigInt|Decimal}
* max {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
* min {number|string|bigint|Decimal}
* max {number|string|bigint|Decimal}
*
*/
function clamp(x, min, max) {
@@ -4254,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|bigInt|Decimal} A value in radians.
* x {number|string|bigint|Decimal} A value in radians.
*
*/
function cos(x) {
@@ -4266,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|bigInt|Decimal} A value in radians.
* x {number|string|bigint|Decimal} A value in radians.
*
*/
function cosh(x) {
@@ -4286,7 +4286,7 @@
* The Decimal constructor and exported function.
* Return a new Decimal instance.
*
* v {number|string|bigInt|Decimal} A numeric value.
* v {number|string|bigint|Decimal} A numeric value.
*
*/
function Decimal(v) {
@@ -4477,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|bigInt|Decimal}
* y {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
* y {number|string|bigint|Decimal}
*
*/
function div(x, y) {
@@ -4490,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|bigInt|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) {
@@ -4501,7 +4501,7 @@
/*
* Return a new Decimal whose value is `x` round to an integer using `ROUND_FLOOR`.
*
* x {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function floor(x) {
@@ -4515,7 +4515,7 @@
*
* hypot(a, b, ...) = sqrt(a^2 + b^2 + ...)
*
* arguments {number|string|bigInt|Decimal}
* arguments {number|string|bigint|Decimal}
*
*/
function hypot() {
@@ -4557,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|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function ln(x) {
@@ -4571,8 +4571,8 @@
*
* log[y](x)
*
* x {number|string|bigInt|Decimal} The argument of the logarithm.
* y {number|string|bigInt|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) {
@@ -4584,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|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function log2(x) {
@@ -4596,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|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function log10(x) {
@@ -4607,7 +4607,7 @@
/*
* Return a new Decimal whose value is the maximum of the arguments.
*
* arguments {number|string|bigInt|Decimal}
* arguments {number|string|bigint|Decimal}
*
*/
function max() {
@@ -4618,7 +4618,7 @@
/*
* Return a new Decimal whose value is the minimum of the arguments.
*
* arguments {number|string|bigInt|Decimal}
* arguments {number|string|bigint|Decimal}
*
*/
function min() {
@@ -4630,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|bigInt|Decimal}
* y {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
* y {number|string|bigint|Decimal}
*
*/
function mod(x, y) {
@@ -4643,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|bigInt|Decimal}
* y {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
* y {number|string|bigint|Decimal}
*
*/
function mul(x, y) {
@@ -4656,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|bigInt|Decimal} The base.
* y {number|string|bigInt|Decimal} The exponent.
* x {number|string|bigint|Decimal} The base.
* y {number|string|bigint|Decimal} The exponent.
*
*/
function pow(x, y) {
@@ -4775,7 +4775,7 @@
*
* To emulate `Math.round`, set rounding to 7 (ROUND_HALF_CEIL).
*
* x {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function round(x) {
@@ -4791,7 +4791,7 @@
* -0 if x is -0,
* NaN otherwise
*
* x {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function sign(x) {
@@ -4804,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|bigInt|Decimal} A value in radians.
* x {number|string|bigint|Decimal} A value in radians.
*
*/
function sin(x) {
@@ -4816,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|bigInt|Decimal} A value in radians.
* x {number|string|bigint|Decimal} A value in radians.
*
*/
function sinh(x) {
@@ -4828,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|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function sqrt(x) {
@@ -4840,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|bigInt|Decimal}
* y {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
* y {number|string|bigint|Decimal}
*
*/
function sub(x, y) {
@@ -4855,7 +4855,7 @@
*
* Only the result is rounded, not the intermediate calculations.
*
* arguments {number|string|bigInt|Decimal}
* arguments {number|string|bigint|Decimal}
*
*/
function sum() {
@@ -4875,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|bigInt|Decimal} A value in radians.
* x {number|string|bigint|Decimal} A value in radians.
*
*/
function tan(x) {
@@ -4887,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|bigInt|Decimal} A value in radians.
* x {number|string|bigint|Decimal} A value in radians.
*
*/
function tanh(x) {
@@ -4898,7 +4898,7 @@
/*
* Return a new Decimal whose value is `x` truncated to an integer.
*
* x {number|string|bigInt|Decimal}
* x {number|string|bigint|Decimal}
*
*/
function trunc(x) {