atan2(), atan2f(), atan2l()

Compute the arctangent, determining the quadrant

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 );

Arguments:

x, y
The value (y/x) for which you want to find the angle.

Library:

libm

Use the -l m option to qcc to link against this library.

Description:

These functions compute the value of the arctangent (in radians) of y/x, using the signs of both arguments to determine the quadrant of the return value. No errors occur if both arguments are zero, or if y is zero.

To check for error situations, use feclearexcept() and fetestexcept():

Returns:

The arctangent of y/x, in the range (-π, π).

If x is: And y is: These functions return:
Negative or -0 ±0 ±π
Positive or +0 ±0 ±0
Finite ±Inf ±π/2
-Inf ±Inf ±3π/4
+Inf ±Inf ±π/4
±0 Negative -π/2
±0 Positive +π/2
-Inf Finite and positive +π
-Inf Finite and negative -π
+Inf Finite and positive +0
+Inf Finite and negative -0
NaN Any value NaN
Any value NaN NaN

Examples:

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

int main( void )
{
    int except_flags;

    feclearexcept(FE_ALL_EXCEPT);

    printf( "%f\n", atan2( .5, 1. ) );

    except_flags = fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW);
    if(except_flags) {
        /* An error occurred; handle it appropriately. */
    }

    return EXIT_SUCCESS;
}

produces the output:

0.463648

Classification:

ANSI, POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes