名前空間
変種
操作

atan2, atan2f, atan2l

提供: cppreference.com
< c‎ | numeric‎ | math
 
 
 
一般的な数学関数
関数
基本操作
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)(C99)(C99)
指数関数
(C99)
(C99)
(C99)
(C99)
冪関数
(C99)
(C99)
三角関数と双曲線関数
(C99)
(C99)
(C99)
誤差関数とガンマ関数
(C99)
(C99)
(C99)
(C99)
最も近い整数
(C99)(C99)(C99)
(C99)
(C99)
(C99)(C99)(C99)
浮動小数点操作関数
(C99)(C99)
(C99)
(C99)
分類
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)
マクロ定数
 
ヘッダ <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
)
) が返されます。
Y引数
戻り値
X引数

定義域エラーが発生した場合、処理系定義の値が返されます。

アンダーフローによる値域エラーが発生した場合、 (丸めた後の) 正しい結果が返されます。

[編集] エラー処理

math_errhandling で規定されている通りにエラーが報告されます。

xy がどちらもゼロの場合、定義域エラーが発生するかもしれません。

処理系が IEEE 浮動小数点算術 (IEC 60559) をサポートしている場合、

  • xy がどちらもゼロであっても、定義域エラーは発生しません。
  • xy がどちらもゼロであっても、値域エラーは発生しません。
  • y がゼロであっても、極エラーは発生しません。
  • y±0x が負または -0 であれば、 ±π が返されます。
  • y±0x が正または +0 であれば、 ±0 が返されます。
  • y±∞x が有限であれば、 ±π/2 が返されます。
  • y±∞x-∞ であれば、 ±3π/4 が返されます。
  • y±∞x+∞ であれば、 ±π/4 が返されます。
  • x±0y が負であれば、 -π/2 が返されます。
  • x±0y が正であれば、 +π/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)
逆正弦 (\({\small\arcsin{x} }\)arcsin(x)) を計算します
(関数) [edit]
(C99)(C99)
逆余弦 (\({\small\arccos{x} }\)arccos(x)) を計算します
(関数) [edit]
(C99)(C99)
逆正接 (\({\small\arctan{x} }\)arctan(x)) を計算します
(関数) [edit]
(C99)(C99)(C99)
複素数の偏角を計算します
(関数) [edit]
https://ja.cppreference.com/mwiki/index.php?title=c/numeric/math/atan2&oldid=37324」から取得

AltStyle によって変換されたページ (->オリジナル) /