public static sum<T extends AbstractNumber>(notnull values as Tuple) as T
Sums a tuple of primitive numbers and complex numbers.
The compiler infers T from all positional types using numeric promotion. An empty tuple returns Int(0). Non-numeric positions and signed/ULong combinations without a common numeric type are rejected with TypeError. An explicit T may widen, but never narrow, the inferred numeric type. A tuple whose positional types have been erased requires an explicit T; its elements are then validated at runtime. No temporary list is created.
| Parameter | Description |
|---|---|
values | Numeric tuple to sum. |
Sum in the inferred or explicitly widened numeric type T.
import klyn.math total = sum((10, 30.1, 3 + 2j)) assert total is Complex<Double> assert total == 43.1 + 2j assert sum((10, 20.5)) == 30.5