-
-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathproduct.go
More file actions
26 lines (21 loc) · 615 Bytes
/
Copy pathproduct.go
File metadata and controls
26 lines (21 loc) · 615 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package stats
import "math"
// Product calculates the product of a slice of floats by
// multiplying the values from left to right. It is the scalar
// counterpart of CumulativeProduct. Large inputs can overflow
// to Inf; use GeometricMean for an overflow-safe summary of
// multiplicative data.
func Product(input Float64Data) (float64, error) {
if input.Len() == 0 {
return math.NaN(), ErrEmptyInput
}
product := 1.0
for _, v := range input {
product *= v
}
return product, nil
}
// Product calculates the product of the data
func (f Float64Data) Product() (float64, error) {
return Product(f)
}