mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
feat: add Abs
This commit is contained in:
1 parent
8f49078eb3
commit
7da931e0a0
5 files changed
+113
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user