1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2026-01-20 07:49:24 +00:00

Fixes FIX-207: enables Decimal.sum(...[]) to return 0 instead throwing an error

This commit is contained in:
Hunter Wilhelm 2025-12-19 09:28:27 -07:00
parent 1a6e845004
commit df3f232448
3 changed files with 6 additions and 3 deletions

View File

@ -4861,7 +4861,8 @@
function sum() {
var i = 0,
args = arguments,
x = new this(args[i]);
firstArg = args[i],
x = new this(firstArg === undefined ? 0 : firstArg);
external = false;
for (; x.s && ++i < args.length;) x = x.plus(args[i]);

View File

@ -4856,7 +4856,8 @@ function sub(x, y) {
function sum() {
var i = 0,
args = arguments,
x = new this(args[i]);
firstArg = args[i],
x = new this(firstArg === undefined ? 0 : firstArg);
external = false;
for (; x.s && ++i < args.length;) x = x.plus(args[i]);

View File

@ -16,7 +16,8 @@ T('sum', function () {
t(11, -11);
t(1, '2', new Decimal(3), new Decimal('4'), -10);
t(new Decimal(-10), '9', new Decimal(0.01), 0.99);
t();
expected = new Decimal(10);
t('10');