gl01/internal/util/absminus.go

19 lines
320 B
Go
Raw Permalink Normal View History

2022-01-20 21:58:50 +08:00
package util
// AbsMinusd returns the value, with the absolute value subtracted
// by minus, or 0 if minus is more than abs.
func AbsMinusd(val, minus float64) float64 {
if val > 0 {
val -= minus
if val < 0 {
val = 0
}
} else {
val += minus
if val > 0 {
val = 0
}
}
return val
}