atan2(3)
โจ NAME โจ
atan2, atan2f, atan2l โ the arc tangent function but make it two variables ๐ (like, the arc tangent of y over x, but with โจquadrant awarenessโจ, iykyk)
๐ LIBRARY ๐
Math library (libm, -lm) โ bestie you HAVE to link it, -lm, don't forget, it's giving "my build failed for 20 minutes" energy ๐ซถ
๐ธ SYNOPSIS ๐ธ
#include <math.h>
double atan2(double y, double x);
float atan2f(float y, float x);
long double atan2l(long double y, long double x);
๐ง Feature Test Macro Requirements for glibc (see feature_test_macros(7))
atan2f(), atan2l():
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
๐ DESCRIPTION ๐
Okay so bestie, these functions calculate the principal value of the arc tangent of y/x, and the way they do it is so smart โ they use the signs of the two arguments to figure out which quadrant the result lives in. No cap, that's the whole point of atan2 versus plain atan. Queen behavior fr fr ๐โจ
๐ RETURN VALUE ๐
On success, these functions return the principal value of the arc tangent of y/x in radians; the return value is in the range [-pi, pi]. Periodt.
Now the iconic edge-case lineup, and you KNOW we're listing all of them because every single one matters ๐
- If y is
+0(-0) and x is less than 0,+pi(-pi) is returned. - If y is
+0(-0) and x is greater than 0,+0(-0) is returned. - If y is less than 0 and x is
+0or-0,-pi/2is returned. - If y is greater than 0 and x is
+0or-0,pi/2is returned. - If either x or y is
NaN, aNaNis returned. ๐ - If y is
+0(-0) and x is-0,+pi(-pi) is returned. - If y is
+0(-0) and x is+0,+0(-0) is returned. - If y is a finite value greater (less) than 0, and x is negative infinity,
+pi(-pi) is returned. - If y is a finite value greater (less) than 0, and x is positive infinity,
+0(-0) is returned. - If y is positive infinity (negative infinity), and x is finite,
pi/2(-pi/2) is returned. - If y is positive infinity (negative infinity) and x is negative infinity,
+3*pi/4(-3*pi/4) is returned. - If y is positive infinity (negative infinity) and x is positive infinity,
+pi/4(-pi/4) is returned.
Like, the signed-zero sweep is chef's kiss ๐ seriously, this function is so careful about -0 and you should be too.
๐ ERRORS ๐
No errors occur. Literally. None. Not even one. It's giving immaculate, flawless, unbothered โจ (which honestly is kind of iconic for a math function โ most of them have opinions, this one just vibes)
๐ ATTRIBUTES ๐
For an explanation of the terms used in this section, see attributes(7).
- Interface:
atan2(),atan2f(),atan2l()โ Attribute: Thread safety โ Value:MT-Safe
So yeah bestie, it's MT-Safe ๐ซถ you can call it from all your threads at once, it does not care, it was BORN for this.
โญ STANDARDS โญ
C11, POSIX.1-2008. Slay ๐ standards-compliant and everything.
๐ฆ HISTORY ๐ฆ
C99, POSIX.1-2001.
The variant returning double also conforms to SVr4, 4.3BSD, C89. Old money fr โ this function has been around since before your grandma's terminal, and it's STILL serving ๐
๐ SEE ALSO ๐
acos(3), asin(3), atan(3), carg(3), cos(3), sin(3), tan(3)
okay that's the whole page bestie, go forth and compute your angles correctly, the quadrant is counting on you ๐
This little love letter to trigonometry was brought to you by Linux man-pages 6.20, dated 2026-02-08, for atan2(3) โ mwah, take care of her ๐ธ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms