How to find the Arc Sine of a given value in Golang?


In this tutorial, we will learn how to find the Arc Sine of a given value in the Golang programming Language. Golang language has many packages with predefined functions that the developer can use without writing the complete logic.

To perform the mathematical operations and logic we have a math package in Golang. We will use this package only to find the Arc Sine of a given value. We will also see how to import the package and also how to call a function this package consists of by writing a Golang code.

Arc Sine

Definition

Arc Sine is a function similar to trigonometry functions. Arc Sine is equal to the inverse of value x. The formula for Arc sine is written below and the value of Arc Sine is at different angles.

Syntax

X = sin^-1(Ө)

Graph


Value of Arc Sine at different angles

  • sin^-1(0) = 0

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

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

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

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

Algorithm

  • Step 1 - Declaring the variable to store the value of the guardian and answer of float32 type.

  • Step 2 - Initializing the variable of a value.

  • Step 3 - Call the function of Arc sine and pass the value.

  • Step 4 - Printing the result.

Example

In this example, we will write a Golang program in which we will import a math package and call the Arc sine function.

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)
} 

Output

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

Algorithm

Step 1 - Declaring the variable to store the value of the guardian and answer of float32 type.

Step 2 - Initializing the variable of a value.

Step 3 - Call the function of Arc sine defined by us and pass the value as a parameter.

Step 4 - Printing the result.

Example

In this example, we will write a Golang program in which we will import a math package and call the Arc sine function in a separate function and call that function 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

Conclusion

These are two ways to find the Arc sine by using the function in the math package and passing the value as a parameter. The second approach will provide abstraction in the program. To learn more about Golang you can explore these tutorials.

Updated on: 29-Nov-2022

88 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements