Atan2()
Published Oct 6, 2023Updated May 15, 2024
Contribute to Docs
The Atan2()
function returns the arctangent value of the y/x value.
Syntax
result := math.Atan2(y,x)
Notes on Atan2()
:
- The ratio of the two arguments
(y/x)
is used to calculate the value of the arctangent. - The
result
will be between -π/2 to π/2 radians. - The value returned will be of type
float64
.
Special Cases
NAN
:
- Atan2(y, NaN) = NaN
- Atan2(NaN, x) = NaN
(+-)0:
- Atan2(+0, x>=0) = +0
- Atan2(-0, x>=0) = -0
- Atan2(y, +Inf) = +0
(+-)π:
- Atan2(+0, x<=-0) = +π
- Atan2(-0, x<=-0) = -π
- Atan2(y>0, -Inf) = +π
- Atan2(y<0, -Inf) = -π
(+-)π/2:
- Atan2(y>0, 0) = +π/2
- Atan2(y<0, 0) = -π/2
- Atan2(+Inf, x) = +π/2
- Atan2(-Inf, x) = -π/2
(+-)π/4:
- Atan2(+Inf, +Inf) = +π/4
- Atan2(-Inf, +Inf) = -π/4
(+-)3π/4:
- Atan2(+Inf, -Inf) = 3π/4
- Atan2(-Inf, -Inf) = -3π/4
Example
The following code calculates the arctangent and prints out the result:
package mainimport ("fmt""math")func main() {x := math.Atan2(-77, 33)fmt.Println(x)y := math.Atan2(33, math.NaN())fmt.Println(y)}
The output will be:
-1.1659045405098132NaN
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Go on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Go
Learn how to use Go (Golang), an open-source programming language supported by Google!Beginner Friendly6 hours