mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
generic
This commit is contained in:
23
mathx/int.go
23
mathx/int.go
@ -1,19 +1,16 @@
|
|||||||
package mathx
|
package mathx
|
||||||
|
|
||||||
// MaxInt returns the larger one of a and b.
|
import (
|
||||||
func MaxInt(a, b int) int {
|
"github.com/charlienet/go-mixed/expr"
|
||||||
if a > b {
|
"golang.org/x/exp/constraints"
|
||||||
return a
|
)
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
// MaxInt returns the larger one of v1 and v2.
|
||||||
|
func Max[T constraints.Ordered](v1, v2 T) T {
|
||||||
|
return expr.If(v1 > v2, v1, v2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinInt returns the smaller one of a and b.
|
// MinInt returns the smaller one of v1 and v2.
|
||||||
func MinInt(a, b int) int {
|
func Min[T constraints.Ordered](v1, v2 T) T {
|
||||||
if a < b {
|
return expr.If(v1 < v2, v1, v2)
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user