mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
d882a11c67
* save * save * save * save
31 lines
408 B
Go
31 lines
408 B
Go
package cmp
|
|
|
|
import (
|
|
"golang.org/x/exp/constraints"
|
|
)
|
|
|
|
// InRange - ensure val is in [min,max] range
|
|
func InRange[T constraints.Ordered](min, max, val T) T {
|
|
if min >= val {
|
|
return min
|
|
}
|
|
if max <= val {
|
|
return max
|
|
}
|
|
return val
|
|
}
|
|
|
|
func Min[T constraints.Ordered](a, b T) T {
|
|
if a <= b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|
|
|
|
func Max[T constraints.Ordered](a, b T) T {
|
|
if a >= b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|