Golang 查找特定数字的反余弦值
Go语言通过math包提供内置支持来执行数字上的基本常量和数学函数的操作。使用math包提供的 Acos()函数 可以找到指定数字的反余弦值。因此,您需要使用import关键字将math包添加到您的程序中,以访问Acos()函数。
语法:
func Acos(y float64) float64
如果y的值<-1或y>1,则Acos(y)=NaN
示例1:
// Golang程序示例,演示如何查找给定数字的反余弦值
package main
import (
"fmt"
"math"
)
// 主函数
func main() {
// 查找给定值的反余弦值
// 使用Acos()函数
res_1 := math.Acos(1)
res_2 := math.Acos(-1)
res_3 := math.Acos(3.3)
// 显示结果
fmt.Printf("结果1:%.1f", res_1)
fmt.Printf("\n结果2:%.1f", res_2)
fmt.Printf("\n结果3:%.1f", res_3)
}
输出:
结果1:0.0
结果2:3.1
结果3:NaN
示例2:
// Golang程序示例,演示如何查找给定数字的反余弦值
package main
import (
"fmt"
"math"
)
// 主函数
func main() {
// 查找给定值的反余弦值
nvalue_1 := math.Acos(1)
nvalue_2 := math.Acos(-1)
// 给定值的和
res := nvalue_1 + nvalue_2
// 显示结果
fmt.Printf("%.1f + %.1f = %.1f",
nvalue_1, nvalue_2, res)
}
输出:
0.0 + 3.1 = 3.1