doc: update doc for mathutil package

This commit is contained in:
dudaodong
2024-03-04 19:52:49 +08:00
parent f7b54986aa
commit a54d4c79a0
4 changed files with 67 additions and 4 deletions

View File

@@ -953,6 +953,14 @@ import "github.com/duke-git/lancet/v2/mathutil"
- **<big>TruncRound</big>** : round off n decimal places for int64.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#TruncRound)]
[[play](https://go.dev/play/p/aumarSHIGzP)]
- **<big>CeilToFloat</big>** : round float up n decimal places.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#CeilToFloat)]
- **<big>CeilToString</big>** : round float up n decimal places, then conver to string.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#CeilToString)]
- **<big>FloorToFloat</big>** : round float down n decimal places.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#FloorToFloat)]
- **<big>FloorToString</big>** : round float down n decimal places, then conver to string.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#FloorToString)]
- **<big>Range</big>** : Creates a slice of numbers from start with specified count, element step is 1.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#Range)]
[[play](https://go.dev/play/p/9ke2opxa8ZP)]
@@ -992,6 +1000,9 @@ import "github.com/duke-git/lancet/v2/mathutil"
- **<big>Abs</big>** : returns the absolute value of param number.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#Sum)]
[[play](https://go.dev/play/p/fsyBh1Os-1d)]
- **<big>Div</big>** : returns the result of x divided by y.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#Div)]
<h3 id="netutil"> 14. Netutil package contains functions to get net information and send http request. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>

View File

@@ -952,6 +952,14 @@ import "github.com/duke-git/lancet/v2/mathutil"
- **<big>TruncRound</big>** : 截短 n 位小数(不进行四舍五入)。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#TruncRound)]
[[play](https://go.dev/play/p/aumarSHIGzP)]
- **<big>CeilToFloat</big>** : 向上舍入进一法保留n位小数。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#CeilToFloat)]
- **<big>CeilToString</big>** : 向上舍入进一法保留n位小数返回字符串。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#CeilToString)]
- **<big>FloorToFloat</big>** : 向下舍入去尾法保留n位小数。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#FloorToFloat)]
- **<big>FloorToString</big>** : 向下舍入去尾法保留n位小数返回字符串。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#FloorToString)]
- **<big>Range</big>** : 根据指定的起始值和数量,创建一个数字切片。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#Range)]
[[play](https://go.dev/play/p/9ke2opxa8ZP)]
@@ -991,6 +999,10 @@ import "github.com/duke-git/lancet/v2/mathutil"
- **<big>Abs</big>** : 求绝对值。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#Sum)]
[[play](https://go.dev/play/p/fsyBh1Os-1d)]
- **<big>Div</big>** : 除法运算。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#Div)]
<h3 id="netutil"> 14. netutil 网络包支持获取 ip 地址,发送 http 请求。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>

View File

@@ -500,7 +500,7 @@ func main() {
### <span id="CeilToFloat">CeilToFloat</span>
<p>向上舍入(进一法),保留 n 位小数</p>
<p>向上舍入(进一法),保留n位小数</p>
<b>函数签名:</b>
@@ -536,7 +536,7 @@ func main() {
### <span id="CeilToString">CeilToString</span>
<p>向上舍入(进一法),保留 n 位小数,返回字符串</p>
<p>向上舍入(进一法),保留n位小数,返回字符串</p>
<b>函数签名:</b>
@@ -572,7 +572,7 @@ func main() {
### <span id="FloorToFloat">FloorToFloat</span>
<p>向下舍入(去尾法),保留 n 位小数</p>
<p>向下舍入(去尾法),保留n位小数</p>
<b>函数签名:</b>
@@ -608,7 +608,7 @@ func main() {
### <span id="FloorToString">FloorToString</span>
<p>向下舍入(去尾法),保留 n 位小数,返回字符串</p>
<p>向下舍入(去尾法),保留n位小数,返回字符串</p>
<b>函数签名:</b>
@@ -1127,3 +1127,38 @@ func main() {
// 0.2
}
```
### <span id="Div">Div</span>
<p>除法运算.</p>
<b>函数签名:</b>
```go
func Div[T constraints.Float | constraints.Integer](x T, y T) float64
```
<b>示例:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/mathutil"
)
func main() {
result1 := mathutil.Div(9, 4)
result2 := mathutil.Div(1, 2)
result3 := mathutil.Div(0, 666)
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
// Output:
// 2.25
// 0.5
// 0
}
```

View File

@@ -101,6 +101,7 @@ func TruncRound[T constraints.Float | constraints.Integer](x T, n int) T {
}
// FloorToFloat round down to n decimal places.
// Play: todo
func FloorToFloat[T constraints.Float | constraints.Integer](x T, n int) float64 {
tmp := math.Pow(10.0, float64(n))
x *= T(tmp)
@@ -109,6 +110,7 @@ func FloorToFloat[T constraints.Float | constraints.Integer](x T, n int) float64
}
// FloorToString round down to n decimal places.
// Play: todo
func FloorToString[T constraints.Float | constraints.Integer](x T, n int) string {
tmp := math.Pow(10.0, float64(n))
x *= T(tmp)
@@ -118,6 +120,7 @@ func FloorToString[T constraints.Float | constraints.Integer](x T, n int) string
}
// CeilToFloat round up to n decimal places.
// Play: todo
func CeilToFloat[T constraints.Float | constraints.Integer](x T, n int) float64 {
tmp := math.Pow(10.0, float64(n))
x *= T(tmp)
@@ -126,6 +129,7 @@ func CeilToFloat[T constraints.Float | constraints.Integer](x T, n int) float64
}
// CeilToString round up to n decimal places.
// Play: todo
func CeilToString[T constraints.Float | constraints.Integer](x T, n int) string {
tmp := math.Pow(10.0, float64(n))
x *= T(tmp)
@@ -387,6 +391,7 @@ func Abs[T constraints.Integer | constraints.Float](x T) T {
}
// Div returns the result of x divided by y.
// Play: todo
func Div[T constraints.Float | constraints.Integer](x T, y T) float64 {
return float64(x) / float64(y)
}