Namespaces
Variants

atan2, atan2f, atan2l

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
ヘッダーで定義 <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) は、実装が __STDC_IEC_60559_DFP__ を事前定義する場合にのみ宣言される(すなわち、実装が十進浮動小数点数をサポートする場合)。

(C23以降)

目次

パラメータ

x, y - 浮動小数点値

戻り値

If no errors occur, the arc tangent of y / x **翻訳結果:** y / x **説明:** - HTMLタグ(` `)と属性(`class`)は翻訳せず保持 - ` `, `
`, ``タグ内ではないが、C++コードとして認識される部分は翻訳対象外
- `y/x`はC++の演算式(除算)であり、C++特有の用語として翻訳せず保持
- 元のフォーマットと構造を完全に維持
( arctan(
y
x
)
) in the range [-π ; +π] radians, is returned.
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 または y のいずれかがNaNの場合、NaNが返される。

注記

atan2 ( y, x ) carg ( x + I * y ) と等価です。

POSIXは アンダーフローが発生した場合、 y / x の値を返すことを規定しており、それがサポートされていない場合は、 DBL_MIN FLT_MIN 、および LDBL_MIN を超えない実装定義の値が返されます。

#include <math.h>
#include <stdio.h>
int main(void)
{
    // 通常の使用法: 2つの引数の符号が象限を決定する
    // atan2(1,1) = +pi/4, 第I象限
    printf("(+1,+1) cartesian is (%f,%f) polar\n", hypot( 1, 1), atan2( 1, 1));
    // atan2(1, -1) = +3pi/4, 第II象限
    printf("(+1,-1) cartesian is (%f,%f) polar\n", hypot( 1,-1), atan2( 1,-1));
    // atan2(-1,-1) = -3pi/4, 第III象限
    printf("(-1,-1) cartesian is (%f,%f) polar\n", hypot(-1,-1), atan2(-1,-1));
    // atan2(-1,-1) = -pi/4, 第IV象限
    printf("(-1,+1) cartesian is (%f,%f) polar\n", hypot(-1, 1), atan2(-1, 1));
    // 特殊な値
    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

参考文献

  • C23規格 (ISO/IEC 9899:2024):
  • 7.12.4.4 atan2関数群 (p: 未定)
  • 7.25 総称数学 <tgmath.h> (p: 未定)
  • F.10.1.4 atan2関数群 (p: 未定)
  • C17規格 (ISO/IEC 9899:2018):
  • 7.12.4.4 atan2関数群 (p: 174)
  • 7.25 総称数学 <tgmath.h> (p: 272-273)
  • F.10.1.4 atan2関数群 (p: 378)
  • C11規格 (ISO/IEC 9899:2011):
  • 7.12.4.4 atan2関数群 (p: 239)
  • 7.25 総称数学 <tgmath.h> (p: 373-375)
  • F.10.1.4 atan2関数群 (p: 519)
  • C99規格 (ISO/IEC 9899:1999):
  • 7.12.4.4 atan2関数 (p: 219)
  • 7.22 型総称数学 <tgmath.h> (p: 335-337)
  • F.9.1.4 atan2関数 (p: 456)
  • C89/C90標準 (ISO/IEC 9899:1990):
  • 4.5.2.4 atan2関数

関連項目

(C99) (C99)
アークサインを計算する ( arcsin(x) )
(関数)
(C99) (C99)
アークコサインを計算する ( arccos(x) )
(関数)
(C99) (C99)
アークタンジェントを計算する ( arctan(x) )
(関数)
(C99) (C99) (C99)
複素数の位相角を計算する
(関数)