代码点读机 / Go / math.Sqrt

math.Sqrt Go · 包功能

返回非负实数的平方根。

怎么用

math.Sqrt(x)

小例子

package main
import (
    "fmt"
    "math"
)

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

运行结果

输出 4

提醒:x 为负数时返回 NaN

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

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