1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-03-01 00:35:28 +08:00

doc: update document for mathutil package

This commit is contained in:
dudaodong
2023-01-02 15:19:47 +08:00
parent 927245e47f
commit 6d57891f66
5 changed files with 80 additions and 32 deletions

View File

@@ -434,18 +434,42 @@ import "github.com/duke-git/lancet/v2/mathutil"
#### Function list: #### Function list:
- [Average](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Average) - **<big>Average</big>** :return average value of numbers.
- [Exponent](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Exponent) [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Average)]
- [Fibonacci](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Fibonacci) [[play](https://go.dev/play/p/Vv7LBwER-pz)]
- [Factorial](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Factorial) - **<big>Exponent</big>** : calculate x^n for int64.
- [Max](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Max) [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Exponent)]
- [MaxBy](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#MaxBy) [[play](https://go.dev/play/p/uF3HGNPk8wr)]
- [Min](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Min) - **<big>Fibonacci</big>** :calculate fibonacci number before n for int.
- [MinBy](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#MinBy) [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Fibonacci)]
- [Percent](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Percent) [[play](https://go.dev/play/p/IscseUNMuUc)]
- [RoundToFloat](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#RoundToFloat) - **<big>Factorial</big>** : calculate x! for uint.
- [RoundToString](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#RoundToString) [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Factorial)]
- [TruncRound](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#TruncRound) [[play](https://go.dev/play/p/tt6LdOK67Nx)]
- **<big>Max</big>** : return maximum value of numbers.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Max)]
[[play](https://go.dev/play/p/cN8DHI0rTkH)]
- **<big>MaxBy</big>** : return the maximum value of a slice using the given comparator function.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#MaxBy)]
[[play](https://go.dev/play/p/pbe2MT-7DV2)]
- **<big>Min</big>** : return minimum value of numbers.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Min)]
[[play](https://go.dev/play/p/21BER_mlGUj)]
- **<big>MinBy</big>** : return the minimum value of a slice using the given comparator function.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#MinBy)]
[[play](https://go.dev/play/p/N9qgYg_Ho6f)]
- **<big>Percent</big>** : calculate the percentage of value to total.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Percent)]
- **<big>RoundToFloat</big>** : round up to n decimal places for float64.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#RoundToFloat)]
[[play](https://go.dev/play/p/ghyb528JRJL)]
- **<big>RoundToString</big>** : round up to n decimal places for float64, return string.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#RoundToString)]
[[play](https://go.dev/play/p/kZwpBRAcllO)]
- **<big>TruncRound</big>** : round off n decimal places for int64.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#TruncRound)]
[[play](https://go.dev/play/p/aumarSHIGzP)]
### 13. Netutil package contains functions to get net information and send http request. ### 13. Netutil package contains functions to get net information and send http request.

View File

@@ -432,18 +432,42 @@ import "github.com/duke-git/lancet/v2/mathutil"
#### Function list: #### Function list:
- [Average](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Average) - **<big>Average</big>** :计算平均数可能需要对结果调用RoundToFloat方法四舍五入。
- [Exponent](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Exponent) [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Average)]
- [Fibonacci](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Fibonacci) [[play](https://go.dev/play/p/Vv7LBwER-pz)]
- [Factorial](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Factorial) - **<big>Exponent</big>** : 指数计算x的n次方
- [Max](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Max) [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Exponent)]
- [MaxBy](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#MaxBy) [[play](https://go.dev/play/p/uF3HGNPk8wr)]
- [Min](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Min) - **<big>Fibonacci</big>** :计算斐波那契数列的第n个数。
- [MinBy](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#MinBy) [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Fibonacci)]
- [Percent](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Percent) [[play](https://go.dev/play/p/IscseUNMuUc)]
- [RoundToFloat](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#RoundToFloat) - **<big>Factorial</big>** : 计算阶乘。
- [RoundToString](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#RoundToString) [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Factorial)]
- [TruncRound](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#TruncRound) [[play](https://go.dev/play/p/tt6LdOK67Nx)]
- **<big>Max</big>** : 返回参数中的最大数。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Max)]
[[play](https://go.dev/play/p/cN8DHI0rTkH)]
- **<big>MaxBy</big>** : 使用给定的比较器函数返回切片的最大值。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#MaxBy)]
[[play](https://go.dev/play/p/pbe2MT-7DV2)]
- **<big>Min</big>** : 返回参数中的最小数。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Min)]
[[play](https://go.dev/play/p/21BER_mlGUj)]
- **<big>MinBy</big>** : 使用给定的比较器函数返回切片的最小值。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#MinBy)]
[[play](https://go.dev/play/p/N9qgYg_Ho6f)]
- **<big>Percent</big>** : 计算百分比可以指定保留n位小数。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Percent)]
- **<big>RoundToFloat</big>** : 四舍五入保留n位小数返回float64。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#RoundToFloat)]
[[play](https://go.dev/play/p/ghyb528JRJL)]
- **<big>RoundToString</big>** : 四舍五入保留n位小数返回string。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#RoundToString)]
[[play](https://go.dev/play/p/kZwpBRAcllO)]
- **<big>TruncRound</big>** : 截短n位小数不进行四舍五入
[[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#TruncRound)]
[[play](https://go.dev/play/p/aumarSHIGzP)]
### 13. netutil 网络包支持获取 ip 地址,发送 http 请求。 ### 13. netutil 网络包支持获取 ip 地址,发送 http 请求。

View File

@@ -218,7 +218,7 @@ func main() {
### <span id="Min">Min</span> ### <span id="Min">Min</span>
<p>Return min value of numbers.</p> <p>Return the minimum value of numbers.</p>
<b>Signature:</b> <b>Signature:</b>
@@ -302,8 +302,8 @@ import (
) )
func main() { func main() {
fmt.Println(mathutil.Percent(1, 2, 2)) //1 fmt.Println(mathutil.Percent(1, 2, 2)) //0.5
fmt.Println(mathutil.Percent(0.1, 0.3, 2)) //33.33 fmt.Println(mathutil.Percent(0.1, 0.3, 2)) //0.33
} }
``` ```

View File

@@ -299,8 +299,8 @@ import (
) )
func main() { func main() {
fmt.Println(mathutil.Percent(1, 2, 2)) //1 fmt.Println(mathutil.Percent(1, 2, 2)) //0.5
fmt.Println(mathutil.Percent(0.1, 0.3, 2)) //33.33 fmt.Println(mathutil.Percent(0.1, 0.3, 2)) //0.33
} }
``` ```

View File

@@ -54,7 +54,7 @@ func Factorial(x uint) uint {
return f return f
} }
// Percent calculate the percentage of val to total. // Percent calculate the percentage of value to total.
func Percent(val, total float64, n int) float64 { func Percent(val, total float64, n int) float64 {
if total == 0 { if total == 0 {
return float64(0) return float64(0)
@@ -113,7 +113,7 @@ func Max[T constraints.Integer | constraints.Float](numbers ...T) T {
return max return max
} }
// MaxBy search the maximum value of a slice using the given comparator function. // MaxBy return the maximum value of a slice using the given comparator function.
// Play: https://go.dev/play/p/pbe2MT-7DV2 // Play: https://go.dev/play/p/pbe2MT-7DV2
func MaxBy[T any](slice []T, comparator func(T, T) bool) T { func MaxBy[T any](slice []T, comparator func(T, T) bool) T {
var max T var max T
@@ -149,7 +149,7 @@ func Min[T constraints.Integer | constraints.Float](numbers ...T) T {
return min return min
} }
// MinBy search the minimum value of a slice using the given comparator function. // MinBy return the minimum value of a slice using the given comparator function.
// Play: https://go.dev/play/p/XuJDKrDdglW // Play: https://go.dev/play/p/XuJDKrDdglW
func MinBy[T any](slice []T, comparator func(T, T) bool) T { func MinBy[T any](slice []T, comparator func(T, T) bool) T {
var min T var min T