x (atan、atanf、および atanl) のアークタンジェントまたは y/x (atan2、atan2f、および atan2l) のアークタンジェントを計算します。
構文
double atan( double x );
float atanf( float x );
long double atanl( long double x );
#define atan(X) // Requires C11 or later
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 later
float atan2( float y, float x ); // C++ only
long double atan2( long double y, long double x ); // C++ only
パラメーター
x, y
任意の数値。
戻り値
atan は、–π/2 から π/2 ラジアンの範囲で x のアークタンジェントを返します。 atan2 では、–π から π ラジアンの範囲で y/x のアークタンジェントを返します。 x が 0 の場合、atan は 0 を返します。 atan2 のパラメーターが両方とも 0 の場合、関数は 0 を返します。 すべての結果はラジアンにあります。
atan2 は、両方のパラメーターの符号を使用して、戻り値のクアドラントを判断します。
| 入力 | SEH 例外 | _matherr 例外 |
|---|---|---|
| ± QNaN、IND | なし | _DOMAIN |
解説
atan 関数は、x のアークタンジェント (逆タンジェント関数) を計算します。 atan2 は y/x のアークタンジェントを計算します (x が 0 と等しい場合、atan2 は π/2 (y が正の場合)、-π/2 (y が負の場合)、または 0 (y が 0 の場合) をそれぞれ返します)。
<tgmath.h>からatanまたはatan2マクロを使用する場合、引数の型によって、選択される関数のバージョンが決まります。 詳細については、「ジェネリック型数値演算」を参照してください。
atan には、ストリーミング SIMD 拡張機能 (SSE2) を使用して実装されています。 SSE2 実装の使い方の詳細および制約については、「_set_SSE2_enable」を参照してください。
C++ ではオーバーロードが可能であるため、float および long double の引数を受け取る atan および atan2 のオーバーロードを呼び出すことができます。 C プログラムでは、<tgmath.h> マクロを使用してこの関数を呼び出す場合を除き、atan および atan2 では常に double の引数を受け取って double を返します。
既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT でのグローバル状態」を参照してください。
要件
| ルーチンによって返される値 | 必須ヘッダー (C) | 必須ヘッダー (C++) |
|---|---|---|
atan、 atan2、 atanf、 atan2f、 atanl、 atan2l |
<math.h> |
<cmath> または <math.h> |
atan、atan2 マクロ |
<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