The Atan2 function in the Go programming language is used to find the arc tangent value of the value, where and are the two parameters.
To use the Atan2 function, you must import the math package in your file and access the Atan2 function within it using the . notation (math.Atan2). Here, Atan2 is the actual function, while math is the Go package that stores the definition of this function.
The definition of the Atan2 function inside the math package is shown below:
The Atan2 function takes two arguments of type float64. The ratio of these two arguments () is then used to calculate the value of the arc tangent.
The Atan2 function returns a single value of type float64 that represents the arc tangent value of the ratio of the arguments (). The possible range of all return values is between -π to π radians.
Below is a list of special cases in the return values:
NAN:
(+-)0:
(+-)π:
(+-)π/2:
(+-)π/4:
(+-)3π/4:
Below is a simple example in which we use the Atan2 function to find the arc tangent value with the parameters -25 and 25:
package mainimport "fmt"import "math"func main() {x := math.Atan2(-25, 25)fmt.Println(x)}
The following example shows that NAN is returned whenever there is NAN in any of the arguments:
package mainimport "fmt"import "math"func main() {x := math.Atan2(math.NaN(), 25)fmt.Println(x)y := math.Atan2(25, math.NaN())fmt.Println(y)}