mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-10 08:29:58 +08:00
optimize: improve breaker algorithm on recovery time (#4077)
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
package mathx
|
||||
|
||||
type numerical interface {
|
||||
type Numerical interface {
|
||||
~int | ~int8 | ~int16 | ~int32 | ~int64 |
|
||||
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
|
||||
~float32 | ~float64
|
||||
}
|
||||
|
||||
// AtLeast returns the greater of x or lower.
|
||||
func AtLeast[T numerical](x, lower T) T {
|
||||
func AtLeast[T Numerical](x, lower T) T {
|
||||
if x < lower {
|
||||
return lower
|
||||
}
|
||||
@@ -15,7 +15,7 @@ func AtLeast[T numerical](x, lower T) T {
|
||||
}
|
||||
|
||||
// AtMost returns the smaller of x or upper.
|
||||
func AtMost[T numerical](x, upper T) T {
|
||||
func AtMost[T Numerical](x, upper T) T {
|
||||
if x > upper {
|
||||
return upper
|
||||
}
|
||||
@@ -23,7 +23,7 @@ func AtMost[T numerical](x, upper T) T {
|
||||
}
|
||||
|
||||
// Between returns the value of x clamped to the range [lower, upper].
|
||||
func Between[T numerical](x, lower, upper T) T {
|
||||
func Between[T Numerical](x, lower, upper T) T {
|
||||
if x < lower {
|
||||
return lower
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user