mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-26 13:48:53 +08:00

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
19 lines
271 B
Go
19 lines
271 B
Go
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
|
|
}
|