1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 15:12:26 +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

@@ -46,6 +46,8 @@ import (
- [Sin](#Sin)
- [Log](#Log)
- [Sum](#Sum)
- [Abs](#Abs)
<div STYLE="page-break-after: always;"></div>
@@ -942,4 +944,40 @@ func main() {
// 3
// 1.1
}
```
### <span id="Abs">Abs</span>
<p>Returns the absolute value of x.</p>
<b>Signature:</b>
```go
func Abs[T constraints.Integer | constraints.Float](x T) T
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/mathutil"
)
func main() {
result1 := Abs(-1)
result2 := Abs(-0.1)
result3 := Abs(float32(0.2))
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
// Output:
// 1
// 0.1
// 0.2
}
```