mirror of
https://github.com/MikeMcl/decimal.js.git
synced 2026-01-20 15:59:23 +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 sqrt(n: Decimal.Value): Decimal;
|
||||||
static sub(x: Decimal.Value, y: 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 sum(n: Decimal.Value[]): Decimal;
|
||||||
static tan(n: Decimal.Value): Decimal;
|
static tan(n: Decimal.Value): Decimal;
|
||||||
static tanh(n: Decimal.Value): Decimal;
|
static tanh(n: Decimal.Value): Decimal;
|
||||||
static trunc(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 sqrt(n: DecimalValue): Decimal;
|
||||||
static sub(x: DecimalValue, y: DecimalValue): Decimal;
|
static sub(x: DecimalValue, y: DecimalValue): Decimal;
|
||||||
static sum(...n: Decimal.Value[]): Decimal;
|
static sum(...n: Decimal.Value[]): Decimal;
|
||||||
|
static sum(n: Decimal.Value[]): Decimal;
|
||||||
static tan(n: DecimalValue): Decimal;
|
static tan(n: DecimalValue): Decimal;
|
||||||
static tanh(n: DecimalValue): Decimal;
|
static tanh(n: DecimalValue): Decimal;
|
||||||
static trunc(n: DecimalValue): Decimal;
|
static trunc(n: DecimalValue): Decimal;
|
||||||
|
|||||||
@ -4856,11 +4856,12 @@
|
|||||||
* Only the result is rounded, not the intermediate calculations.
|
* Only the result is rounded, not the intermediate calculations.
|
||||||
*
|
*
|
||||||
* arguments {number|string|bigint|Decimal}
|
* arguments {number|string|bigint|Decimal}
|
||||||
|
* arguments {(number|string|bigint|Decimal)[]}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function sum() {
|
function sum() {
|
||||||
var i = 0,
|
var i = 0,
|
||||||
args = arguments,
|
args = arguments.length === 1 && Array.isArray(arguments[0]) ? arguments[0] : arguments,
|
||||||
x = new this(args[i]);
|
x = new this(args[i]);
|
||||||
|
|
||||||
external = false;
|
external = false;
|
||||||
|
|||||||
@ -4851,11 +4851,12 @@ function sub(x, y) {
|
|||||||
* Only the result is rounded, not the intermediate calculations.
|
* Only the result is rounded, not the intermediate calculations.
|
||||||
*
|
*
|
||||||
* arguments {number|string|bigint|Decimal}
|
* arguments {number|string|bigint|Decimal}
|
||||||
|
* arguments {(number|string|bigint|Decimal)[]}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function sum() {
|
function sum() {
|
||||||
var i = 0,
|
var i = 0,
|
||||||
args = arguments,
|
args = arguments.length === 1 && Array.isArray(arguments[0]) ? arguments[0] : arguments,
|
||||||
x = new this(args[i]);
|
x = new this(args[i]);
|
||||||
|
|
||||||
external = false;
|
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>
|
<p>
|
||||||
<code>x</code>: <i>number|string|bigInt|Decimal</i><br />
|
<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>
|
||||||
<p>
|
<p>
|
||||||
Returns a new Decimal whose value is the sum of the <code>arguments</code>,
|
Returns a new Decimal whose value is the sum of the arguments (either passed as
|
||||||
rounded to <a href='#precision'><code>precision</code></a> significant digits using
|
variadic arguments or as an array), rounded to <a href='#precision'><code>precision</code></a>
|
||||||
rounding mode <a href='#rounding'><code>rounding</code></a>.<br />
|
significant digits using rounding mode <a href='#rounding'><code>rounding</code></a>.<br />
|
||||||
Only the result is rounded, not the intermediate summations.
|
Only the result is rounded, not the intermediate summations.
|
||||||
</p>
|
</p>
|
||||||
<pre>
|
<pre>
|
||||||
x = 5
|
x = 5
|
||||||
y = '16'
|
y = '16'
|
||||||
z = new Decimal(-11)
|
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(1, 0, '-1');
|
||||||
t(0, new Decimal('-10'), 0, 0, 0, 0, 0, 10);
|
t(0, new Decimal('-10'), 0, 0, 0, 0, 0, 10);
|
||||||
t(11, -11);
|
t(11, -11);
|
||||||
|
t([11, -11]);
|
||||||
|
t([0]);
|
||||||
t(1, '2', new Decimal(3), new Decimal('4'), -10);
|
t(1, '2', new Decimal(3), new Decimal('4'), -10);
|
||||||
t(new Decimal(-10), '9', new Decimal(0.01), 0.99);
|
t(new Decimal(-10), '9', new Decimal(0.01), 0.99);
|
||||||
|
|
||||||
@ -24,6 +26,7 @@ T('sum', function () {
|
|||||||
t(10, 0);
|
t(10, 0);
|
||||||
t(0, 0, 0, 0, 0, 0, 10);
|
t(0, 0, 0, 0, 0, 0, 10);
|
||||||
t(11, -1);
|
t(11, -1);
|
||||||
|
t([11, -1]);
|
||||||
t(1, '2', new Decimal(3), new Decimal('4'));
|
t(1, '2', new Decimal(3), new Decimal('4'));
|
||||||
t('9', new Decimal(0.01), 0.99);
|
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, new Decimal('-Infinity'), '9', new Decimal(0), 11);
|
||||||
t(0, '9', new Decimal(0), 11, -Infinity);
|
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);
|
||||||
|
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