go Cos(),余弦

Cos()方法语法

func Cos(x float64) float64

go源码对Cos()方法的介绍:

Cos returns the cosine of the radian argument x.

Special cases are:

Cos(±Inf) = NaN
Cos(NaN) = NaN

golang标准库math.Cos()方法,接收一个类型为float64且为弧度制值的参数x,并返回该参数的余弦值。除此之外,Cos(±Inf) = NaN;Cos(NaN) = NaN。


math.Cos()方法实例代码

下方实例求取的是30°角的余弦值,该角度通过Cos()中的表达式转换为弧度制值:

func main() {
	cos_value := math.Cos(30 * math.Pi / 180)
	fmt.Println(cos_value)
}

运行go文件,得到输出:

0.8660254037844386

全栈后端 / go语法 :













Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.