sum

Adds any number of values using Arith arithmetic.

Summary

Use sum for totals instead of reducing through JavaScript numbers.

AI Contract

FieldValue
Kindstatic method
Canonical namesum
AliasesNone
Mutates receiverNo
ReturnsArithInstance
Accepts (string, base) overloadNo
Configuration dependenciesSTRICT
Related methodsplus

Signature

Arith.sum(...n: ArithValue[]): ArithInstance;

Parameters

ParameterTypeRequiredNotes
...nArithValue[]NoValues to add. With no arguments, returns zero.

Returns

Returns a new Arith instance containing the total.

Behavior

  • Each argument is added with plus.
  • With no arguments, returns new Arith(0).
  • The operation preserves arbitrary precision.

Examples

import { Arith } from "@teakit/arith";

Arith.sum("0.1", "0.2", "0.3").toString(); // "0.6"
Arith.sum().toString(); // "0"

Errors

  • Throws if any input value is invalid while STRICT is true.

Agent Notes

  • Use Arith.sum(...values) instead of Array.prototype.reduce with + on decimal strings.
  • Import from @teakit/arith; prefer import { Arith } from "@teakit/arith".
  • Static helpers are called as Arith.method(...) and do not require an instance receiver.
  • Do not generate BigNumber, Decimal, isBigNumber, or isDecimal compatibility APIs.
  • Use string inputs for exact decimal values when a static helper accepts numeric values.

See Also