🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## Ceil 向上取整 ~~~ func Ceil(x float64) float64 ~~~ ~~~ f := 3.14 fmt.Println(math.Ceil(f)) // 4 ~~~ ## Floor 向下取整 ~~~ func Floor(x float64) float64 ~~~ ~~~ f := 3.14 fmt.Println(math.Floor(f)) // 3 ~~~ ## IsNaN 判断 f 是否表示一个NaN(Not A Number)值 ~~~ func IsNaN(f float64) (is bool) ~~~ ~~~ f := 3.14 fmt.Println(math.IsNaN(f)) // false ~~~ ## Trunc 返回浮点数的整数部分 ~~~ func Trunc(x float64) float64 ~~~ ~~~ f := 3.9 fmt.Println(math.Trunc(f)) // 3 ~~~ ## Abs 获取绝对值 ~~~ func Abs(x float64) float64 ~~~ ~~~ f := -996.007 fmt.Println(math.Abs(f)) // 996.007 ~~~ ## Max 返回两个浮点数中的最大值 ~~~ func Max(x, y float64) float64 ~~~ ~~~ fmt.Println(math.Max(3.1415926, 3.1414)) // 3.1415926 ~~~ ## Min 返回两个浮点数中的最小值 ~~~ func Min(x, y float64) float64 ~~~ ~~~ fmt.Println(math.Min(3.1415926, 3.1414)) // 3.1414 ~~~ ## Dim 如果x-y大于0,则返回差值,否则返回0 ~~~ func Dim(x, y float64) float64 ~~~ ~~~ fmt.Println(math.Dim(3.1415926, 3.1414)) // 0.00019260000000009825 fmt.Println(math.Dim(3.1415926, 3.1416)) // 0 ~~~ ### Mod 取余 ~~~ func Mod(x, y float64) float64 ~~~ ~~~ fmt.Println(math.Mod(9, 4)) // 1 ~~~ ## Sqrt 返回x的二次方根 ~~~ func Sqrt(x float64) float64 ~~~ ~~~ fmt.Println(math.Sqrt(9)) // 3 ~~~ ## Cbrt 返回x的三次方根 ~~~ func Cbrt(x float64) float64 ~~~ ~~~ fmt.Println(math.Cbrt(8)) // 2 ~~~ ## Pow 返回 x 的 y 次方 ~~~ func Pow(x, y float64) float64 ~~~ ~~~ fmt.Println(math.Pow(9, 2)) // 81 ~~~