GoLang – Find Arc Tangent – Atan2() Function – Examples & Explanation

Atan2() function is used to find the arc tangent for the given inputs (y/x – parameters) in Go language.
The standard math package of Go programming language has Atan2() function. The purpose of this function is to find the arc tangent of y/x and it will also find the quadrant of the return value (output) by using the signs of both arguments (x and y).

Syntax of Atan2() Function in Go Language

The syntax of Atan2() function in Go Language is:

Note: float64 is a data type in Go language which has IEEE-754 64-bit floating-point numbers.
Special cases are:

Atan2(y, NaN) = NaN
Atan2(NaN, x) = NaN
Atan2(+0, x>=0) = +0
Atan2(-0, x>=0) = -0
Atan2(+0, x<=-0) = +Pi
Atan2(-0, x<=-0) = -Pi Atan2(y>0, 0) = +Pi/2
Atan2(y<0, 0) = -Pi/2 Atan2(+Inf, +Inf) = +Pi/4 Atan2(-Inf, +Inf) = -Pi/4 Atan2(+Inf, -Inf) = 3Pi/4 Atan2(-Inf, -Inf) = -3Pi/4 Atan2(y, +Inf) = 0 Atan2(y>0, -Inf) = +Pi
Atan2(y<0, -Inf) = -Pi
Atan2(+Inf, x) = +Pi/2
Atan2(-Inf, x) = -Pi/2


Parameters of Atan2() Function in Go Language

x , y – Where both x and y is any Valid float64 Input value. These parameters are required.


Error Handling

If the x or y parameter are not numbers (numeric values) Atan2() function returns an error .
If there is no argument (x,y – input value) passes to the function, then the compiler will produce an error.


Return Value of Atan2() Function in Go Language

Atan2() function will returns the arc tangent of the given inputs(x and y– parameters). It uses the signs of two inputs to determine the quadrant of then return value.


GoLang Atan2() Function Example 1



GoLang Atan2() Function Example 2



GoLang Atan2() Function Example 3