gl01/internal/util/absminus.go
2022-01-20 21:58:50 +08:00

19 lines
320 B
Go

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
}