Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

atan2 — C23 library function

`atan2(double y, double x)` from `<math.h>` returns the directional angle of point `(x, y)` from the positive x-axis, in radians in the interval `-π` through `π`. Its arguments are ordered `y` first, then `x`.

Version: C23

Syntax

double atan2(double y, double x);

atan2(double y, double x) from <math.h> returns the directional angle of point (x, y) from the positive x-axis, in radians in the interval -π through π. Its arguments are ordered y first, then x.

Unlike atan(y / x), it preserves quadrant information and handles a vertical direction without division. The example actually calls atan2(1.0, 0.0) and obtains approximately π/2.

Base C23 permits a domain error when both arguments are zero, and a range error may occur when x > 0 and nonzero y / x is so close to zero that the correct result underflows. All exact signed-zero axis results, infinity quadrant results, and NaN propagation described above are Annex F guarantees for IEC 60559, not portable base-C23 guarantees.

Examples

#include <math.h>
#include <stdio.h>

int main(void) {
    double radians = atan2(1.0, 0.0);
    printf("%.3f\n", radians);
    return 0;
}

Result

1.571

Unlike `atan(y / x)`, it preserves quadrant information and handles a vertical direction without division. The example actually calls `atan2(1.0, 0.0)` and obtains approximately `π/2`.

Sources