feat: add Abs

This commit is contained in:
dudaodong committed 2023-06-27 10:24:35 +08:00
1 parent 8f49078eb3
commit 7da931e0a0
5 files changed
+113

No files matched your search

+10
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
}