Skip to main content

sum

sum(numbers: List<Integer>) : Integer
sum(numbers: List<Float>) : Float

The sum of a list of integer numbers or a list of floating-point numbers.

  • For example, on integers, sum([1, 2, 3]) equals 6.
  • Likewise, on floats, sum([1.1, 2.1, 3.1]) equals 6.300000000000001.
    • Keep in mind that floating-point arithmetic is generally not precise!
  • You can define a list in various ways, not just as a list of literal numbers. See List for more detail on working with lists.
    • Importantly, a list's elements must all be of the same type. As such, sum([1.1, 2, 3.1]) has a type-error since the list is not well-formed. The fix is to replace integer 2 with 2.0 or 2. to have it be treated as a float.
    • You can use int and float to convert to integers and to floats, respectively.

See also

Types

Functions