tan, tanf, tanl
来自 cppreference.cn
定义于头文件 <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 起) |
目录 |
[编辑] 参数
arg | - | 表示弧度角的浮点值 |
[编辑] 返回值
如果没有错误发生,则返回 arg 的正切值 (tan(arg))。
如果 arg 的量级较大,结果可能没有或只有很少的意义。 |
(直到 C99) |
如果发生域错误,则返回实现定义的值 (支持 NaN 时返回 NaN)。
如果因下溢发生范围错误,则返回正确结果(舍入后)。
[编辑] 错误处理
错误按 math_errhandling
中指定的方式报告。
如果实现支持 IEEE 浮点算术 (IEC 60559)
- 如果参数是 ±0,则原样返回;
- 如果参数是 ±∞,则返回 NaN 并引发 FE_INVALID;
- 如果参数为 NaN,则返回 NaN。
[编辑] 注意
C 标准中没有将参数为无穷大的情况指定为域错误,但在 POSIX 中定义为域错误。
该函数在 π(1/2 + n) 处有数学极点;但是,没有常见的浮点表示能够精确表示 π/2
,因此没有参数值会导致极点错误。
[编辑] 示例
运行此代码
#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
[编辑] 参考
- C23 标准 (ISO/IEC 9899:2024)
- 7.12.4.7 tan 函数 (p: TBD)
- 7.25 类型通用数学 <tgmath.h> (p: TBD)
- F.10.1.7 tan 函数 (p: TBD)
- C17 标准 (ISO/IEC 9899:2018)
- 7.12.4.7 tan 函数 (p: 175)
- 7.25 类型通用数学 <tgmath.h> (p: 272-273)
- F.10.1.7 tan 函数 (p: 378)
- C11 标准 (ISO/IEC 9899:2011)
- 7.12.4.7 tan 函数 (p: 240)
- 7.25 类型通用数学 <tgmath.h> (p: 373-375)
- F.10.1.7 tan 函数 (p: 519)
- C99 标准 (ISO/IEC 9899:1999)
- 7.12.4.7 tan 函数 (p: 220)
- 7.22 类型通用数学 <tgmath.h> (p: 335-337)
- F.9.1.7 tan 函数 (p: 457)
- C89/C90 标准 (ISO/IEC 9899:1990)
- 4.5.2.7 tan 函数
[编辑] 另请参阅
(C99)(C99) |
计算正弦 (sin(x)) (函数) |
(C99)(C99) |
计算余弦 (cos(x)) (函数) |
(C99)(C99) |
计算反正切 (arctan(x)) (函数) |
(C99)(C99)(C99) |
计算复正切 (函数) |
C++ 文档 关于 tan
|