You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
196 B
Go
18 lines
196 B
Go
3 years ago
|
package util
|
||
|
|
||
|
import (
|
||
|
"golang.org/x/exp/constraints"
|
||
|
)
|
||
|
|
||
|
type Numeric interface {
|
||
|
constraints.Float | constraints.Integer
|
||
|
}
|
||
|
|
||
|
func Abs[T Numeric](a T) T {
|
||
|
if a < 0 {
|
||
|
return -a
|
||
|
}
|
||
|
|
||
|
return a
|
||
|
}
|