atan Functions

Description

Calculate the arctangent of x (atan and _atanl) and the arctangent of y/x (atan2 and _atan2l).

#include <math.h>

double atan( double x );

double atan2( double y, double x );

long double _atanl( long double x );

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

x, y Any number  

Remarks

The atan family of functions calculates the arctangent of x, and the atan2 family of functions calculates the arctangent of y/x. The atan group returns a value in the range –p/2 to p/2 radians, and the atan2 group returns a value in the range Ôp to p radians. The atan2 functions use the signs of both arguments to determine the quadrant of the return value. The atan2 functions are well defined for every point other than the origin, even if x equals 0 and y does not equal 0.

Return Value

The atan family of functions returns the arctangent result. If both arguments of atan2 or _atan2l are 0, the function sets errno to EDOM, prints a _DOMAIN error message to stderr, and returns 0.

Error handling can be modified by using the _matherr (or _matherrl) routine.

Compatibility

atan, atan2

Standards:ANSI, UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

_atanl, _atan2l

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

See Also

acos functions, asin functions, cos functions, _matherr, sin functions, tan functions

Example

/* ATAN.C: This program calculates the arctangent of 1 and -1. */

#include <math.h>

#include <stdio.h>

#include <errno.h>

void main( void )

{

double x1, x2, y;

printf( "Enter a real number: " );

scanf( "%lf", &x1 );

y = atan( x1 );

printf( "Arctangent of %f: %f\n", x1, y );

printf( "Enter a second real number: " );

scanf( "%lf", &x2 );

y = atan2( x1, x2 );

printf( "Arctangent of %f / %f: %f\n", x1, x2, y );

}

Output

Enter a real number: -862.42

Arctangent of -862.420000: -1.569637

Enter a second real number: 78.5149

Arctangent of -862.420000 / 78.514900: -1.480006