floats: add Min and Max

This commit is contained in:
c9s 2022-08-30 18:14:28 +08:00
parent e6d4faea6a
commit bea5b27402
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -165,3 +165,36 @@ func MinMax(inReal []float64, inTimePeriod int) (outMin []float64, outMax []floa
} }
return outMin, outMax return outMin, outMax
} }
func Min(values []float64) float64 {
if len(values) == 0 {
return 0.0
}
var min = values[0]
for _, b := range values {
if b < min {
min = b
}
}
return min
}
func Max(values []float64) float64 {
if len(values) == 0 {
return 0.0
}
var max = values[0]
for _, b := range values {
if b > max {
max = b
}
}
return max
}