geom/ints/math.go

72 lines
991 B
Go
Raw Normal View History

package ints
// Abs returns the absolute value of i.
func Abs(i int) int {
if 0 > i {
return -i
}
return i
}
// Min returns the minimum of a and b.
func Min(a, b int) int {
if a < b {
return a
}
return b
}
// Min64 returns the minimum of a and b.
func Min64(a, b int64) int64 {
if a < b {
return a
}
return b
}
// Max returns the maximum of a and b.
func Max(a, b int) int {
if a > b {
return a
}
return b
}
// Max64 returns the maximum of a and b.
func Max64(a, b int64) int64 {
if a > b {
return a
}
return b
}
// Norm returns the normalized value of i (-1, 0 or 1).
func Norm(i int) int {
if i < 0 {
return -1
}
if i > 0 {
return 1
}
return 0
}
// Norm64 returns the normalized value of i (-1, 0 or 1).
func Norm64(i int64) int64 {
if i < 0 {
return -1
}
if i > 0 {
return 1
}
return 0
}
// SubAbs subtracts a from b and returns the absolute value of the result.
func SubAbs(a, b int) int {
if a > b {
return a - b
}
return b - a
}