Files
opencloud/vendor/github.com/gookit/goutil/mathutil/compare.go
dependabot[bot] 0df009eae0 Bump github.com/gookit/config/v2 from 2.2.3 to 2.2.4
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.3 to 2.2.4.
- [Release notes](https://github.com/gookit/config/releases)
- [Commits](https://github.com/gookit/config/compare/v2.2.3...v2.2.4)

---
updated-dependencies:
- dependency-name: github.com/gookit/config/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-03 10:26:28 +01:00

77 lines
1.2 KiB
Go

package mathutil
import (
"math"
"github.com/gookit/goutil/comdef"
)
// Min compare two value and return max value
func Min[T comdef.XintOrFloat](x, y T) T {
if x < y {
return x
}
return y
}
// Max compare two value and return max value
func Max[T comdef.XintOrFloat](x, y T) T {
if x > y {
return x
}
return y
}
// SwapMin compare and always return [min, max] value
func SwapMin[T comdef.XintOrFloat](x, y T) (T, T) {
if x < y {
return x, y
}
return y, x
}
// SwapMax compare and always return [max, min] value
func SwapMax[T comdef.XintOrFloat](x, y T) (T, T) {
if x > y {
return x, y
}
return y, x
}
// MaxInt compare and return max value
func MaxInt(x, y int) int {
if x > y {
return x
}
return y
}
// SwapMaxInt compare and return max, min value
func SwapMaxInt(x, y int) (int, int) {
if x > y {
return x, y
}
return y, x
}
// MaxI64 compare and return max value
func MaxI64(x, y int64) int64 {
if x > y {
return x
}
return y
}
// SwapMaxI64 compare and return max, min value
func SwapMaxI64(x, y int64) (int64, int64) {
if x > y {
return x, y
}
return y, x
}
// MaxFloat compare and return max value
func MaxFloat(x, y float64) float64 {
return math.Max(x, y)
}