mirror of
https://github.com/MikeMcl/decimal.js.git
synced 2026-01-21 16:29:25 +00:00
Fixes FIX-207: enables Decimal.sum(...[]) to return 0 instead throwing an error
This commit is contained in:
parent
1a6e845004
commit
df3f232448
@ -4861,7 +4861,8 @@
|
|||||||
function sum() {
|
function sum() {
|
||||||
var i = 0,
|
var i = 0,
|
||||||
args = arguments,
|
args = arguments,
|
||||||
x = new this(args[i]);
|
firstArg = args[i],
|
||||||
|
x = new this(firstArg === undefined ? 0 : firstArg);
|
||||||
|
|
||||||
external = false;
|
external = false;
|
||||||
for (; x.s && ++i < args.length;) x = x.plus(args[i]);
|
for (; x.s && ++i < args.length;) x = x.plus(args[i]);
|
||||||
|
|||||||
@ -4856,7 +4856,8 @@ function sub(x, y) {
|
|||||||
function sum() {
|
function sum() {
|
||||||
var i = 0,
|
var i = 0,
|
||||||
args = arguments,
|
args = arguments,
|
||||||
x = new this(args[i]);
|
firstArg = args[i],
|
||||||
|
x = new this(firstArg === undefined ? 0 : firstArg);
|
||||||
|
|
||||||
external = false;
|
external = false;
|
||||||
for (; x.s && ++i < args.length;) x = x.plus(args[i]);
|
for (; x.s && ++i < args.length;) x = x.plus(args[i]);
|
||||||
|
|||||||
@ -16,6 +16,7 @@ T('sum', function () {
|
|||||||
t(11, -11);
|
t(11, -11);
|
||||||
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);
|
||||||
|
t();
|
||||||
|
|
||||||
expected = new Decimal(10);
|
expected = new Decimal(10);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user