mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
floats: add Min and Max
This commit is contained in:
parent
e6d4faea6a
commit
bea5b27402
|
@ -165,3 +165,36 @@ func MinMax(inReal []float64, inTimePeriod int) (outMin []float64, outMax []floa
|
|||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user