sum.go 268 B

123456789101112131415161718
  1. package stats
  2. import "math"
  3. // Sum adds all the numbers of a slice together
  4. func Sum(input Float64Data) (sum float64, err error) {
  5. if input.Len() == 0 {
  6. return math.NaN(), EmptyInput
  7. }
  8. // Add em up
  9. for _, n := range input {
  10. sum += n
  11. }
  12. return sum, nil
  13. }