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


In this tutorial, we will learn how to find the Arc Tangent 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 Tangent 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 Tangent

Definition

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

Syntax

X = tan^-1(Ө)

Graph


Value of Arc Tangent at different angles

  • tan^-1(1) = 0

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

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

  • tan^-1(1/2) = ㄫ / 3

  • tan^-1(0) = ㄫ / 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 Tangent 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 Tangent 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 Tangent of a given value in the Golang programming language using a math package.")
   
   // initializing the value of the variable value
   value = 1
   
   // finding Arc Tangent for the given value 
   answer = math.Atan(value)
   
   // printing the result
   fmt.Println("The Arc Tangent value with the value of", value, "is", answer)
} 

Output

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

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 Tangent 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 Tangent 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"
)
type of float64
func ArcTangent(angle float64) float64 {
   
   // returning the Arc Tangent of the angle
   return math.Atan(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 Tangent 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 Tangent for the given value in a separate function
   answer = ArcTangent(value)
   
   // printing the result
   fmt.Println("The Arc Tangent value with the value of", value, "is", answer)
} 
Program to find the Arc Tangent of a given value in the Golang programming language using a separate function in the same program.
The Arc Tangent value with the value of 1 is 0.7853981633974483

Conclusion

These are two ways to find the Arc Tangent 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

92 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements