Golang 如何找到给定值的反正弦值

Golang 如何找到给定值的反正弦值

在本教程中,我们将学习如何在Golang编程语言中找到给定值的反正弦值。Golang语言具有许多预定义函数的软件包,开发人员可以在不编写完整逻辑的情况下使用。

要执行数学运算和逻辑操作,我们在Golang中有一个 math 软件包。我们将仅使用此软件包来找到给定值的反正弦值。我们还将看到如何导入软件包以及如何通过编写Golang代码调用此包中包含的函数。

反正弦

定义

反正弦是一种类似于三角函数的函数。反正弦等于值x的倒数。反正弦的公式如下所示,并且反正弦值在不同的角度上有所不同。

语法

X = sin^-1(Ө)

图表

Golang 如何找到给定值的反正弦值

不同角度的反正弦值

  • sin^-1(0) = 0

  • sin^-1(1/2) = ㄫ / 6

  • sin^-1(1/√2) = ㄫ / 4

  • sin^-1(√3/2) = ㄫ / 3

  • sin^-1(1) = ㄫ / 2

步骤

  • 步骤1 - 声明一个变量来存储保护者的值和float32类型的答案。

  • 步骤2 - 初始化变量的值。

  • 步骤3 - 调用反正弦函数并传入值。

  • 步骤4 - 打印结果。

示例

在这个示例中,我们将编写一个Golang程序,导入math包并调用Arc sine函数。

package main
import (

   // fmt package provides the function to print anything
   "fmt"

   // math package provides multiple functions for different

   // mathematical operations
   "math"
)
func main() {

   // declaring the variables to store the value of \value and answer
   var value, answer float64
   fmt.Println("Program to find the Arc sine of a given    value in the Golang programming language using a math package.")

   // initializing the value of the variable value
   value = 1

   // finding Arc sine for the given value
   answer = math.Asin(value)

   // printing the result
   fmt.Println("The Arc sine value with the value of", value, "is", answer)
}

输出

Program to find the Arc sine of a given    value in the Golang programming language using a math package.
The Arc sine value with the value of 1 is 1.5707963267948966

步骤

步骤1 - 声明一个变量来存储guardian的值和类型为float32的答案。

步骤2 - 初始化一个值的变量。

步骤3 - 调用我们定义的Arc sine函数并将值作为参数传入。

步骤4 - 打印结果。

示例

在这个示例中,我们将编写一个Golang程序,导入一个 math 包,并在一个单独的函数中调用Arc sine函数并调用该函数main。

package main
import (

   // fmt package provides the function to print anything
   "fmt"

   // math package provides multiple functions for different

   // mathematical operations
   "math"
)

// this is a function with a parameter of float64 type and a return type of float64
func ArcSine(angle float64) float64 {

   // returning the Arc Sine of the angle
   return math.Asin(angle)
}
func main() {

   // declaring the variables to store the value of value and answer
   var value, answer float64
   fmt.Println("Program to find the Arc Sine of a given value in the Golang programming language using a separate function in the same program.")

   // initializing the value of the value
   value = 1

   // finding Arc sine for the given value in a separate function
   answer = ArcSine(value)

   // printing the result
   fmt.Println("The Arc Sine value with the value of", value, "is", answer)
}
Program to find the Arc Sine of a given value in the Golang programming language using a separate function in the same program.
The Arc Sine value with the value of 1 is 1.5707963267948966

结论

这是使用数学包中的函数并将值作为参数传递来找到反正弦的两种方法。第二种方法将为程序提供抽象。要了解更多关于Golang的信息,您可以探索这些 教程。

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程