tan, tanf, tanl
提供: cppreference.com
ヘッダ <math.h> で定義 | ||
float tanf(float arg ); | (1) | (C99以上) |
double tan(double arg ); | (2) | |
longdouble tanl(longdouble arg ); | (3) | (C99以上) |
ヘッダ <tgmath.h> で定義 | ||
#define tan( arg ) | (4) | (C99以上) |
1-3) (ラジアンで測った)
arg
の正接を計算します。4) 型総称マクロ。 引数が longdouble 型の場合は
tanl
が呼ばれます。 そうでなく、引数が整数型または double 型の場合は tan
が呼ばれます。 そうでなければ tanf
が呼ばれます。 引数が複素数の場合、マクロは対応する複素数の関数 (ctanf, ctan, ctanl) を呼びます。目次 |
[編集]引数
arg | - | ラジアンで角度を表す浮動小数点値 |
[編集]戻り値
エラーが発生しなければ、 arg
の正接 (tan(arg)) が返されます。
| (C99未満) |
定義域エラーが発生した場合、処理系定義の値 (サポートされていれば NaN) が返されます。
アンダーフローによる値域エラーが発生した場合、 (丸めた後の) 正しい結果が返されます。
[編集]エラー処理
math_errhandling で規定されている通りにエラーが報告されます。
処理系が IEEE 浮動小数点算術 (IEC 60559) をサポートしている場合、
- 引数が ±0 であれば、それが変更されずに返されます。
- 引数が ±∞ であれば、 NaN が返され、 FE_INVALID が発生します。
- 引数が NaN であれば、 NaN が返されます。
[編集]ノート
引数が無限大のケースは C では定義域エラーであると規定されていませんが、POSIX では定義域エラーとして定義されています。
この関数は π(1/2 + n) に数学的な極を持ちますが、一般的な浮動小数点表現は π/2 を正確に表現することはできず、そのため極エラーが発生する引数の値はありません。
[編集]例
Run this code
#include <stdio.h>#include <math.h>#include <errno.h>#include <fenv.h> #pragma STDC FENV_ACCESS ONint main(void){double pi =acos(-1);// typical usageprintf("tan (pi/4) = %+f\n", tan( pi/4));// 45 degprintf("tan(3*pi/4) = %+f\n", tan(3*pi/4));// 135 degprintf("tan(5*pi/4) = %+f\n", tan(5*pi/4));// -135 degprintf("tan(7*pi/4) = %+f\n", tan(7*pi/4));// -45 deg// special valuesprintf("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/4) = +1.000000 tan(3*pi/4) = -1.000000 tan(5*pi/4) = +1.000000 tan(7*pi/4) = -1.000000 tan(+0) = 0.000000 tan(-0) = -0.000000 tan(INFINITY) = -nan FE_INVALID raised
[編集]参考文献
- C11 standard (ISO/IEC 9899:2011):
- 7.12.4.7 The tan functions (p: 240)
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
- F.10.1.7 The tan functions (p: 519)
- C99 standard (ISO/IEC 9899:1999):
- 7.12.4.7 The tan functions (p: 220)
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
- F.9.1.7 The tan functions (p: 457)
- C89/C90 standard (ISO/IEC 9899:1990):
- 4.5.2.7 The tan function
[編集]関連項目
(C99)(C99) | 正弦 (sin(x)) を計算します (関数) |
(C99)(C99) | 余弦 (cos(x)) を計算します (関数) |
(C99)(C99) | 逆正接 (arctan(x)) を計算します (関数) |
(C99)(C99)(C99) | 複素正接を計算します (関数) |
tan の C++リファレンス |