You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
271 B
19 lines
271 B
2 years ago
|
package stats
|
||
|
|
||
|
import "math"
|
||
|
|
||
|
// Sum adds all the numbers of a slice together
|
||
|
func Sum(input Float64Data) (sum float64, err error) {
|
||
|
|
||
|
if input.Len() == 0 {
|
||
|
return math.NaN(), EmptyInputErr
|
||
|
}
|
||
|
|
||
|
// Add em up
|
||
|
for _, n := range input {
|
||
|
sum += n
|
||
|
}
|
||
|
|
||
|
return sum, nil
|
||
|
}
|