tan, tanf, tanl
From cppreference.com
| ヘッダー <math.h> で定義 |
||
| float tanf( float arg ); |
(1) | (C99以降) |
| double tan( double arg ); |
(2) | |
| long double tanl( long double arg ); |
(3) | (C99以降) |
| _Decimal32 tand32( _Decimal32 arg ); |
(4) | (C23以降) |
| _Decimal64 tand64( _Decimal64 arg ); |
(5) | (C23以降) |
| _Decimal128 tand128( _Decimal128 arg ); |
(6) | (C23以降) |
| ヘッダー <tgmath.h> で定義 |
||
| #define tan( arg ) |
(7) | (C99以降) |
1-6) arg (ラジアン単位)のタンジェントを計算します。
7) 型汎用マクロ:引数の型が long double の場合、(3) (
tanl)が呼び出されます。それ以外の場合で、引数が整数型または double 型の場合、(2) (tan)が呼び出されます。それ以外の場合、(1) (tanf)が呼び出されます。引数が複素数の場合、マクロは対応する複素数関数(ctanf, ctan, ctanl)を呼び出します。|
関数 (4-6) は、実装が |
(C23以降) |
目次 |
[edit] パラメータ
| arg | - | ラジアン単位の角度を表す浮動小数点値 |
[edit] 戻り値
エラーが発生しない場合、arg のタンジェント(tan(arg))が返されます。
|
arg の絶対値が大きい場合、結果はほとんど、または全く意味を持たない可能性があります。 |
(C99まで) |
領域エラーが発生した場合、実装定義の値が返される (サポートされている場合はNaN)。
アンダーフローによる範囲エラーが発生した場合、正確な結果 (丸め後) が返される。
[edit] エラー処理
エラーは math_errhandling で指定されたとおりに報告されます。
実装が IEEE 浮動小数点演算 (IEC 60559) をサポートしている場合
- 引数が ±0 の場合、変更されずに返されます。
- 引数が ±∞ の場合、NaN が返され、FE_INVALID が発生します。
- 引数が NaN の場合、NaN が返されます。
[edit] 注釈
引数が無限大の場合、Cではドメインエラーとして指定されていませんが、POSIX ではドメインエラーとして定義されています。
この関数は π(1/2 + n) で数学的な極を持ちますが、一般的な浮動小数点数表現では π/2 を正確に表現できないため、極エラーが発生する引数の値はありません。
[edit] 例
このコードを実行
#include <errno.h> #include <fenv.h> #include <math.h> #include <stdio.h> #ifndef __GNUC__ #pragma STDC FENV_ACCESS ON #endif int main(void) { const double pi = acos(-1); // typical usage printf("tan(pi*1/4) = %+f\n", tan(pi * 1 / 4)); // 45 deg printf("tan(pi*3/4) = %+f\n", tan(pi * 3 / 4)); // 135 deg printf("tan(pi*5/4) = %+f\n", tan(pi * 5 / 4)); // -135 deg printf("tan(pi*7/4) = %+f\n", tan(pi * 7 / 4)); // -45 deg // special values printf("tan(+0) = %f\n", tan(0.0)); printf("tan(-0) = %f\n", tan(-0.0)); // error handling feclearexcept(FE_ALL_EXCEPT); printf("tan(INFINITY) = %f\n", tan(INFINITY)); if (fetestexcept(FE_INVALID)) puts(" FE_INVALID raised"); }
実行結果の例
tan(pi*1/4) = +1.000000
tan(pi*3/4) = -1.000000
tan(pi*5/4) = +1.000000
tan(pi*7/4) = -1.000000
tan(+0) = 0.000000
tan(-0) = -0.000000
tan(INFINITY) = -nan
FE_INVALID raised[edit] 参照
- C23標準 (ISO/IEC 9899:2024)
- 7.12.4.7 The tan functions (p: TBD)
- 7.25 Type-generic math <tgmath.h> (p: TBD)
- F.10.1.7 The tan functions (p: TBD)
- C17標準 (ISO/IEC 9899:2018)
- 7.12.4.7 The tan functions (p: 175)
- 7.25 型総称数学関数 <tgmath.h> (p: 272-273)
- F.10.1.7 The tan functions (p: 378)
- C11標準 (ISO/IEC 9899:2011)
- 7.12.4.7 The tan functions (p: 240)
- 7.25 型総称数学関数 <tgmath.h> (p: 373-375)
- F.10.1.7 The tan functions (p: 519)
- C99標準 (ISO/IEC 9899:1999)
- 7.12.4.7 The tan functions (p: 220)
- 7.22 型総称数学関数 <tgmath.h> (p: 335-337)
- F.9.1.7 The tan functions (p: 457)
- C89/C90標準 (ISO/IEC 9899:1990)
- 4.5.2.7 The tan function
[edit] 関連項目
| (C99)(C99) |
サインを計算する (sin(x)) (関数) |
| (C99)(C99) |
コサインを計算する (cos(x)) (関数) |
| (C99)(C99) |
アークタンジェントを計算する (arctan(x)) (関数) |
| (C99)(C99)(C99) |
複素タンジェントを計算する (関数) |
| C++ ドキュメント (tan)
| |