Share via


atan, atanf, atanl, atan2, atan2f, atan2l

計算 x 的反正切值 (atanatanfatanl) 或 y/x 的反正切值 (atan2atan2fatan2l)。

語法

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

參數

x, y
任何數字。

傳回值

atan 會傳回範圍 -π/2 中的 反正切值 x ,以傳回 π/2 弧度。 atan2會傳回範圍 -π 中的 反正切值 y/x ,以π弧度。 如果 x 為 0,則 atan 傳回 0。 如果 atan2 的兩個參數都是 0,則函式會傳回 0。 所有結果都以弧度為單位。

atan2 使用這兩個參數的符號來判斷傳回值的象限。

輸入 SEH 例外狀況 _matherr 例外
± QNaN,IND none _DOMAIN

備註

atan 函式會計算 x 的反正切值 (反向 tangent 函式)。 atan2 計算 y/x 的反正切值 (如果 x 等於 0,atan2 會傳回 π/2;如果 y 是正值,則為 -π/2;如果 y 為負值或 0,則 y 為 0)。

如果您使用 atan 的 或 atan2<tgmath.h> ,引數的類型會決定選取哪一個函式版本。 如需詳細資訊,請參閱 類型泛型數學

atan 具有使用 Streaming SIMD Extensions 2 (SSE2) 的實作。 如需使用 SSE2 實作的相關資訊和限制,請參閱 _set_SSE2_enable

因為 C++ 允許多載,因此您可以呼叫 和 的多載 atan ,並 atan2 接受 floatlong double 引數。 在 C 程式中,除非您使用 <tgmath.h> 宏來呼叫此函式, atan 而且 atan2 一律接受 double 引數並傳回 double

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

常式 必要的標頭 (C) 必要的標頭 (C++)
atan, atan2, atanf, atan2f, atanl, atan2l <math.h> <cmath><math.h>
atanatan2 <tgmath.h>

範例

// 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

另請參閱

數學和浮點支援
acos, acosf, acosl
asin, asinf, asinl
cos, cosf, cosl
_matherr
sin, sinf, sinl
tan, tanf, tanl
_CIatan
_CIatan2