atan2, atan2f, atan2l
From cppreference.com
| ヘッダー <math.h> で定義 |
||
| float atan2f( float y, float x ); |
(1) | (C99以降) |
| double atan2( double y, double x ); |
(2) | |
| long double atan2l( long double y, long double x ); |
(3) | (C99以降) |
| _Decimal32 atan2d32( _Decimal32 y, _Decimal32 x ); |
(4) | (C23以降) |
| _Decimal64 atan2d64( _Decimal64 y, _Decimal64 x ); |
(5) | (C23以降) |
| _Decimal128 atan2d128( _Decimal128 y, _Decimal128 x ); |
(6) | (C23以降) |
| ヘッダー <tgmath.h> で定義 |
||
| #define atan2( y, x ) |
(7) | (C99以降) |
1-6) y / x の逆正接を計算し、引数の符号を用いて正しい象限を決定します。
7) 型汎用マクロ: いずれかの引数が long double 型の場合、(3) (
atan2l) が呼び出されます。それ以外の場合で、いずれかの引数が整数型または double 型の場合、(2) (atan2) が呼び出されます。それ以外の場合は、(1) (atan2f) が呼び出されます。|
関数 (4-6) は、実装が |
(C23以降) |
目次 |
[edit] パラメータ
| x, y | - | floating-point value |
[edit] 戻り値
エラーが発生しない場合、y / x の逆正接 (arctan(| y |
| x |
ドメインエラーが発生した場合、実装定義の値が返されます。
アンダーフローによる範囲エラーが発生した場合、正確な結果 (丸め後) が返される。
[edit] エラー処理
エラーは math_errhandling で指定されたとおりに報告されます。
x と y が両方ともゼロの場合、定義域エラーが発生する可能性があります。
実装が IEEE 浮動小数点演算 (IEC 60559) をサポートしている場合
- x と y が両方ともゼロの場合、定義域エラーは発生しません。
- x と y が両方ともゼロの場合、範囲エラーも発生しません。
- y がゼロの場合、極エラーは発生しません。
- y が
±0で x が負または-0の場合、±πが返されます。 - y が
±0で x が正または+0の場合、±0が返されます。 - y が
±∞で x が有限の場合、±π/2が返されます。 - y が
±∞で x が-∞の場合、±3π/4が返されます。 - y が
±∞で x が+∞の場合、±π/4が返されます。 - x が
±0で y が負の場合、-π/2が返されます。 - x が
±0で y が正の場合、+π/2が返されます。 - x が
-∞で y が有限で正の場合、+πが返されます。 - x が
-∞で y が有限で負の場合、-πが返されます。 - x が
+∞で y が有限で正の場合、+0が返されます。 - x が
+∞で y が有限で負の場合、-0が返されます。 - x または y のいずれかが NaN の場合、NaN が返されます。
[edit] 注釈
atan2(y, x) は、carg(x + I*y) と同等です。
POSIX では、アンダーフローの場合、y / x が返され、それがサポートされない場合は、実装定義値で DBL_MIN、FLT_MIN、および LDBL_MIN 以下の値が返されると規定されています。
[edit] 例
このコードを実行
#include <math.h> #include <stdio.h> int main(void) { // normal usage: the signs of the two arguments determine the quadrant // atan2(1,1) = +pi/4, Quad I printf("(+1,+1) cartesian is (%f,%f) polar\n", hypot( 1, 1), atan2( 1, 1)); // atan2(1, -1) = +3pi/4, Quad II printf("(+1,-1) cartesian is (%f,%f) polar\n", hypot( 1,-1), atan2( 1,-1)); // atan2(-1,-1) = -3pi/4, Quad III printf("(-1,-1) cartesian is (%f,%f) polar\n", hypot(-1,-1), atan2(-1,-1)); // atan2(-1,-1) = -pi/4, Quad IV printf("(-1,+1) cartesian is (%f,%f) polar\n", hypot(-1, 1), atan2(-1, 1)); // special values printf("atan2(0, 0) = %f atan2(0, -0)=%f\n", atan2(0,0), atan2(0,-0.0)); printf("atan2(7, 0) = %f atan2(7, -0)=%f\n", atan2(7,0), atan2(7,-0.0)); }
出力
(+1,+1) cartesian is (1.414214,0.785398) polar (+1,-1) cartesian is (1.414214,2.356194) polar (-1,-1) cartesian is (1.414214,-2.356194) polar (-1,+1) cartesian is (1.414214,-0.785398) polar atan2(0, 0) = 0.000000 atan2(0, -0)=3.141593 atan2(7, 0) = 1.570796 atan2(7, -0)=1.570796
[edit] 参考文献
- C23標準 (ISO/IEC 9899:2024)
- 7.12.4.4 The atan2 functions (p: TBD)
- 7.25 Type-generic math <tgmath.h> (p: TBD)
- F.10.1.4 The atan2 functions (p: TBD)
- C17標準 (ISO/IEC 9899:2018)
- 7.12.4.4 The atan2 functions (p: 174)
- 7.25 型総称数学関数 <tgmath.h> (p: 272-273)
- F.10.1.4 The atan2 functions (p: 378)
- C11標準 (ISO/IEC 9899:2011)
- 7.12.4.4 The atan2 functions (p: 239)
- 7.25 型総称数学関数 <tgmath.h> (p: 373-375)
- F.10.1.4 The atan2 functions (p: 519)
- C99標準 (ISO/IEC 9899:1999)
- 7.12.4.4 The atan2 functions (p: 219)
- 7.22 型総称数学関数 <tgmath.h> (p: 335-337)
- F.9.1.4 The atan2 functions (p: 456)
- C89/C90標準 (ISO/IEC 9899:1990)
- 4.5.2.4 The atan2 function
[edit] 関連項目
| (C99)(C99) |
アークサインを計算する (arcsin(x)) (関数) |
| (C99)(C99) |
アークコサインを計算する (arccos(x)) (関数) |
| (C99)(C99) |
アークタンジェントを計算する (arctan(x)) (関数) |
| (C99)(C99)(C99) |
複素数の偏角を計算する (関数) |
| C++ ドキュメント for atan2
| |