代码点读机 / Go / math

math Go · 常用包

Go 标准库里的数学函数包:提供平方根、绝对值、幂运算、三角函数、圆周率等常用数学运算。

怎么用

import "math"; math.Sqrt/Abs/Pow/Pi 等

小例子

package main
import (
    "fmt"
    "math"
)

func main() {
    fmt.Println(math.Sqrt(16), math.Pi)
}

运行结果

输出 4 3.141592653589793

提醒:math 包函数参数和返回值大多是 float64

官方文档:https://pkg.go.dev/math

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Go全部词条