carta
atan2l(3)

atan2l3

Arc tangent and complex phase angle functions

Part of atan2(3).

Usage

double

float

long double

double

float

long double

Library

Math Library (libm, -lm)

Overview

The atan2(), atan2f(), and atan2l() functions compute the principal value of the arc tangent of y/x, using the signs of both arguments to determine the quadrant of the return value.

The carg(), cargf(), and cargl() functions compute the complex argument (or phase angle) of z. The complex argument is the number theta such that z = r * e^(I * theta), where r = cabs(z). The call carg(z) is equivalent to atan2(cimag(z), creal(z)), and similarly for cargf() and cargl().

Return values

The atan2(), atan2f(), and atan2l() functions, if successful, return the arc tangent of y/x in the range[-, +] radians. Here are some of the special cases:

atan2(y, x, No, :=)
sign(y)*( -

Notes

The function atan2() defines "if x > 0," atan2(0, 0) = 0 despite that previously atan2(0, 0) may have generated an error message. The reasons for assigning a value to atan2(0, 0) are these:

  1. Programs that test arguments to avoid computing atan2(0, 0) must be indifferent to its value. Programs that require it to be invalid are vulnerable to diverse reactions to that invalidity on diverse computer systems.

  2. The atan2() function is used mostly to convert from rectangular (x,y) to polar coordinates that must satisfy x = and y = These equations are satisfied when (x=0,y=0) is mapped to (r=0,theta=0). In general, conversions to polar coordinates should be computed thus:

    r	:= hypot(x,y);  ... := sqrt(x∗x+y∗y)
    theta	:= atan2(y,x).
  3. The foregoing formulas need not be altered to cope in a reasonable way with signed zeros and infinities on a machine that conforms to IEEE 754; the versions of hypot(3) and atan2() provided for such a machine are designed to handle all cases. That is why atan2(±0, -0) = ± for instance. In general the formulas above are equivalent to these:

    r := sqrt(x∗x+y∗y); if r = 0 then x := copysign(1,x);

History

  • FreeBSD 16.0-CURRENT (2026-10-27) to FreeBSD 15.0-RELEASE: the text shown here
  • FreeBSD 14.5-RELEASE to FreeBSD 13.3-RELEASE
  • FreeBSD 13.2-RELEASE to FreeBSD 13.1-RELEASE
  • FreeBSD 13.0-RELEASE
  • FreeBSD 12.4-RELEASE
  • FreeBSD 12.3-RELEASE
  • FreeBSD 12.2-RELEASE
  • FreeBSD 12.1-RELEASE
  • FreeBSD 12.0-RELEASE
  • FreeBSD 11.4-RELEASE
  • FreeBSD 11.3-RELEASE
  • FreeBSD 11.2-RELEASE
  • FreeBSD 11.1-RELEASE
  • FreeBSD 11.0-RELEASE
  • FreeBSD 10.4-RELEASE
  • FreeBSD 10.3-RELEASE
  • FreeBSD 10.2-RELEASE
  • FreeBSD 10.1-RELEASE
  • FreeBSD 10.0-RELEASE
  • FreeBSD 9.3-RELEASE
  • FreeBSD 9.2-RELEASE
  • FreeBSD 9.1-RELEASE
  • FreeBSD 9.0-RELEASE
  • FreeBSD 8.4-RELEASE
  • FreeBSD 8.3-RELEASE
  • FreeBSD 8.2-RELEASE
  • FreeBSD 8.1-RELEASE
  • FreeBSD 8.0-RELEASE

Standards

The atan2(), atan2f(), atan2l(), carg(), cargf(), and cargl() functions conform to ISO/IEC 9899:1999 (“ISO C99”).

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.