atan2l Function

Calculates the trigonometric arc tangent function of y/x.

Include

<math.h>

Prototype

long double atan2l(long double y, long double x);

Arguments

y
y value for which to return the arc tangent
x
x value for which to return the arc tangent

Return Value

Returns the arc tangent in radians in the range [-π, +π] (inclusive) with the quadrant determined by the signs of both parameters.

Remarks

A domain error occurs if both x and y are zero.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

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

int main(void)
{
  long double x, y, z;

  errno = 0;
  x = 0.0;
  y = 2.0;
  z = atan2l(y, x);
  if (errno)
    perror("Error");
  printf("The arctangent of %Lf/%Lf is %Lf\n", y, x, z);

  errno = 0;
  x = -1.0;
  y = 0.0;
  z = atan2l(y, x);
  if (errno)
    perror("Error");
  printf("The arctangent of %Lf/%Lf is %Lf\n", y, x, z);

  errno = 0;
  x = 0.0;
  y = 0.0;
  z = atan2l(y, x);
  if (errno)
    perror("Error");
  printf("The arctangent of %Lf/%Lf is %Lf\n", y, x, z);
}

Example Output

The arctangent of 2.000000/0.000000 is 1.570796
The arctangent of 0.000000/-1.000000 is 3.141593
Error: domain error
The arctangent of 0.000000/0.000000 is nan