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
Atan2()
function in Go Language is:
func Atan2(y, x float64) float64
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
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
package main import "fmt" import "math" func main() { var x float64 x = math.Atan2(0,0) fmt.Println(x) }
Output:
0
GoLang Atan2()
Function Example 2
package main import "fmt" import "math" func main() { var x float64 x = math.Atan2(-8,9) fmt.Println(x) }
Output:
-0.7266423406817255
GoLang Atan2()
Function Example 3
package main import "fmt" import "math" func main() { var x float64 x = math.Atan2(10,4) fmt.Println(x) }
Output:
1.1902899496825317