mirror of
https://github.com/MikeMcl/decimal.js.git
synced 2026-01-20 07:49:24 +00:00
Merge 03a4d8675b into 1a6e845004
This commit is contained in:
commit
cb15300ecb
1
decimal.d.ts
vendored
1
decimal.d.ts
vendored
@ -270,6 +270,7 @@ export declare class Decimal {
|
||||
static sqrt(n: Decimal.Value): Decimal;
|
||||
static sub(x: Decimal.Value, y: Decimal.Value): Decimal;
|
||||
static sum(...n: Decimal.Value[]): Decimal;
|
||||
static sum(n: Decimal.Value[]): Decimal;
|
||||
static tan(n: Decimal.Value): Decimal;
|
||||
static tanh(n: Decimal.Value): Decimal;
|
||||
static trunc(n: Decimal.Value): Decimal;
|
||||
|
||||
1
decimal.global.d.ts
vendored
1
decimal.global.d.ts
vendored
@ -291,6 +291,7 @@ export declare class Decimal {
|
||||
static sqrt(n: DecimalValue): Decimal;
|
||||
static sub(x: DecimalValue, y: DecimalValue): Decimal;
|
||||
static sum(...n: Decimal.Value[]): Decimal;
|
||||
static sum(n: Decimal.Value[]): Decimal;
|
||||
static tan(n: DecimalValue): Decimal;
|
||||
static tanh(n: DecimalValue): Decimal;
|
||||
static trunc(n: DecimalValue): Decimal;
|
||||
|
||||
@ -4856,11 +4856,12 @@
|
||||
* Only the result is rounded, not the intermediate calculations.
|
||||
*
|
||||
* arguments {number|string|bigint|Decimal}
|
||||
* arguments {(number|string|bigint|Decimal)[]}
|
||||
*
|
||||
*/
|
||||
function sum() {
|
||||
var i = 0,
|
||||
args = arguments,
|
||||
args = arguments.length === 1 && Array.isArray(arguments[0]) ? arguments[0] : arguments,
|
||||
x = new this(args[i]);
|
||||
|
||||
external = false;
|
||||
|
||||
@ -4851,11 +4851,12 @@ function sub(x, y) {
|
||||
* Only the result is rounded, not the intermediate calculations.
|
||||
*
|
||||
* arguments {number|string|bigint|Decimal}
|
||||
* arguments {(number|string|bigint|Decimal)[]}
|
||||
*
|
||||
*/
|
||||
function sum() {
|
||||
var i = 0,
|
||||
args = arguments,
|
||||
args = arguments.length === 1 && Array.isArray(arguments[0]) ? arguments[0] : arguments,
|
||||
x = new this(args[i]);
|
||||
|
||||
external = false;
|
||||
|
||||
15
doc/API.html
15
doc/API.html
@ -861,22 +861,25 @@ a.equals(b) // true</pre>
|
||||
|
||||
|
||||
|
||||
<h5 id="Dsum">sum<code class='inset'>.sum(x [, y, ...]) <i>⇒ Decimal</i></code></h5>
|
||||
<h5 id="Dsum">sum<code class='inset'>.sum(x [, y, ...]) <i>⇒ Decimal</i></code><br />
|
||||
<code class='inset'>.sum([x, y, ...]) <i>⇒ Decimal</i></code></h5>
|
||||
<p>
|
||||
<code>x</code>: <i>number|string|bigInt|Decimal</i><br />
|
||||
<code>y</code>: <i>number|string|bigInt|Decimal</i>
|
||||
<code>y</code>: <i>number|string|bigInt|Decimal</i><br />
|
||||
<code>[x, y, ...]</code>: <i>Array<number|string|bigInt|Decimal></i>
|
||||
</p>
|
||||
<p>
|
||||
Returns a new Decimal whose value is the sum of the <code>arguments</code>,
|
||||
rounded to <a href='#precision'><code>precision</code></a> significant digits using
|
||||
rounding mode <a href='#rounding'><code>rounding</code></a>.<br />
|
||||
Returns a new Decimal whose value is the sum of the arguments (either passed as
|
||||
variadic arguments or as an array), rounded to <a href='#precision'><code>precision</code></a>
|
||||
significant digits using rounding mode <a href='#rounding'><code>rounding</code></a>.<br />
|
||||
Only the result is rounded, not the intermediate summations.
|
||||
</p>
|
||||
<pre>
|
||||
x = 5
|
||||
y = '16'
|
||||
z = new Decimal(-11)
|
||||
Decimal.sum(x, y, z) // '10'</pre>
|
||||
Decimal.sum(x, y, z) // '10'
|
||||
Decimal.sum([x, y, z]) // '10'</pre>
|
||||
|
||||
|
||||
|
||||
|
||||
@ -14,6 +14,8 @@ T('sum', function () {
|
||||
t(1, 0, '-1');
|
||||
t(0, new Decimal('-10'), 0, 0, 0, 0, 0, 10);
|
||||
t(11, -11);
|
||||
t([11, -11]);
|
||||
t([0]);
|
||||
t(1, '2', new Decimal(3), new Decimal('4'), -10);
|
||||
t(new Decimal(-10), '9', new Decimal(0.01), 0.99);
|
||||
|
||||
@ -24,6 +26,7 @@ T('sum', function () {
|
||||
t(10, 0);
|
||||
t(0, 0, 0, 0, 0, 0, 10);
|
||||
t(11, -1);
|
||||
t([11, -1]);
|
||||
t(1, '2', new Decimal(3), new Decimal('4'));
|
||||
t('9', new Decimal(0.01), 0.99);
|
||||
|
||||
@ -61,4 +64,9 @@ T('sum', function () {
|
||||
t(0, new Decimal('-Infinity'), '9', new Decimal(0), 11);
|
||||
t(0, '9', new Decimal(0), 11, -Infinity);
|
||||
t(4, new Decimal(-Infinity), 0, '9', new Decimal(0), -Infinity, 2);
|
||||
t([4, new Decimal(-Infinity), 0, '9', new Decimal(0), -Infinity, 2]);
|
||||
|
||||
expected = new Decimal(100e3);
|
||||
|
||||
t(Array.from({ length: 100e3 }).fill(1));
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user