1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-10 15:52:27 +08:00

feat: add Abs

This commit is contained in:
dudaodong
2023-06-27 10:24:35 +08:00
parent 8f49078eb3
commit 7da931e0a0
5 changed files with 113 additions and 0 deletions

View File

@@ -341,3 +341,13 @@ func Sin(radian float64, precision ...int) float64 {
func Log(n, base float64) float64 {
return math.Log(n) / math.Log(base)
}
// Abs returns the absolute value of x.
// Play: todo
func Abs[T constraints.Integer | constraints.Float](x T) T {
if x < 0 {
return (-x)
}
return x
}