atan, atanf, atanl, atan2, atan2f, atan2l

Calcula el arco tangente de x (atan, atanf y atanl) o el arco tangente de y/x (atan2, atan2f y atan2l).

Sintaxis

double atan( double x );
float atanf( float x );
long double atanl( long double x );
#define atan(X) // Requires C11 or higher

float atan( float x );  // C++ only
long double atan( long double x );  // C++ only

double atan2( double y, double x );
float atan2f( float y, float x );
long double atan2l( long double y, long double x );
#define atan2(Y, X) // Requires C11 or higher

float atan2( float y, float x );  // C++ only
long double atan2( long double y, long double x );  // C++ only

Parámetros

x, y
Cualquier número.

Valor devuelto

atan devuelve el arco tangente de x en el intervalo comprendido entre -π/2 y π/2 radianes. atan2 devuelve el arco tangente de y/x en el intervalo comprendido entre -π y π radianes. Si x es 0, atan devuelve 0. Si los dos parámetros de atan2 son 0, la función devuelve 0. Todos los resultados están en radianes.

atan2 utiliza los signos de los dos parámetros para determinar el cuadrante del valor devuelto.

Entrada Excepción SEH Excepción de _matherr
± QNaN, IND None _DOMAIN

Comentarios

La función atan calcula el arco tangente (función tangente inversa) de x. atan2 calcula el arco tangente de y/x (si x es igual a 0, atan2 devuelve π/2 si y es positivo, devuelve - π/2 si y es negativo, y devuelve 0 si y es 0).

Si usa la atan macro o atan2 de <tgmath.h>, el tipo del argumento determina qué versión de la función está seleccionada. Consulte Matemáticas de tipo genérico para obtener más información.

atan tiene una implementación que usa las Extensiones SIMD de transmisión por secuencias 2 (SSE2). Para obtener información y las restricciones sobre el uso de la implementación de SSE2, vea _set_SSE2_enable.

Como C++ permite las sobrecargas, puede llamar a las sobrecargas de atan y atan2, que toman los argumentos float y long double. En un programa de C, a menos que use la macro <tgmath.h> para llamar a esta función, atan y atan2 siempre toman argumentos double y devuelven un valor double.

De manera predeterminada, el estado global de esta función está limitado a la aplicación. Para cambiar este comportamiento, consulte Estado global en CRT.

Requisitos

Routine Encabezado necesario (C) Encabezado necesario (C++)
atan, atan2, atanf, atan2f, atanl, atan2l <math.h> <cmath> o <math.h>
Macros atan, atan2 <tgmath.h>

Ejemplo

// crt_atan.c
// arguments: 5 0.5
#include <math.h>
#include <stdio.h>
#include <errno.h>

int main( int ac, char* av[] )
{
   double x, y, theta;
   if( ac != 3 ){
      fprintf( stderr, "Usage: %s <x> <y>\n", av[0] );
      return 1;
   }
   x = atof( av[1] );
   theta = atan( x );
   printf( "Arctangent of %f: %f\n", x, theta );
   y = atof( av[2] );
   theta = atan2( y, x );
   printf( "Arctangent of %f / %f: %f\n", y, x, theta );
   return 0;
}
Arctangent of 5.000000: 1.373401
Arctangent of 0.500000 / 5.000000: 0.099669

Consulte también

Compatibilidad con matemáticas y punto flotante
acos, acosf, acosl
asin, asinf, asinl
cos, cosf, cosl
_matherr
sin, sinf, sinl
tan, tanf, tanl
_CIatan
_CIatan2