atan2, atan2f, atan2l
提供: 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以上) |
ヘッダ <tgmath.h> で定義
|
||
#define atan2( arg ) |
(4) | (C99以上) |
1-3) 正しい象限を判定するために引数の符号を使用して、
y/x
の逆正接を計算します。4) 型総称マクロ。 引数が long double 型の場合は
atan2l
が呼ばれます。 そうでなく、引数が整数型または double 型の場合は atan2
が呼ばれます。 そうでなければ atan2f
が呼ばれます。目次 |
[編集] 引数
x, y | - | 浮動小数点値 |
[編集] 戻り値
エラーが発生しなければ、範囲 [-π ; +π] ラジアン内のy/x
の逆正接 (arctan(y |
x |
定義域エラーが発生した場合、処理系定義の値が返されます。
アンダーフローによる値域エラーが発生した場合、 (丸めた後の) 正しい結果が返されます。
[編集] エラー処理
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
が NaN であるかy
が NaN であれば、 NaN が返されます。
[編集] ノート
atan2(y, x) は carg(x + I*y) と同等です。
POSIX は、アンダーフローの場合、 y/x
が返される値となり、それがサポートされない場合、 DBL_MIN、 FLT_MIN、 LDBL_MIN より大きくない処理系定義の値が返されると規定しています。
[編集] 例
Run this code
#include <stdio.h> #include <math.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
[編集] 参考文献
- C11 standard (ISO/IEC 9899:2011):
- 7.12.4.4 The atan2 functions (p: 239)
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
- F.10.1.4 The atan2 functions (p: 519)
- C99 standard (ISO/IEC 9899:1999):
- 7.12.4.4 The atan2 functions (p: 219)
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
- F.9.1.4 The atan2 functions (p: 456)
- C89/C90 standard (ISO/IEC 9899:1990):
- 4.5.2.4 The atan2 function
[編集] 関連項目
(C99)(C99) |
逆正弦 (arcsin(x)) を計算します (関数) |
(C99)(C99) |
逆余弦 (arccos(x)) を計算します (関数) |
(C99)(C99) |
逆正接 (arctan(x)) を計算します (関数) |
(C99)(C99)(C99) |
複素数の偏角を計算します (関数) |
atan2 の C++リファレンス
|