cosh, coshf, coshl
来自 cppreference.cn
定义于头文件 <math.h> |
||
float coshf( float arg ); |
(1) | (C99 起) |
double cosh( double arg ); |
(2) | |
long double coshl( long double arg ); |
(3) | (C99 起) |
定义于头文件 <tgmath.h> |
||
#define cosh( arg ) |
(4) | (C99 起) |
1-3) 计算
arg
的双曲余弦。4) 类型泛型宏:如果参数类型为 long double,则调用
coshl
。否则,如果参数具有整数类型或 double 类型,则调用 cosh
。否则,调用 coshf
。如果参数是复数,则宏调用相应的复数函数 (ccoshf, ccosh, ccoshl)。目录 |
[编辑] 参数
arg | - | 浮点值,表示双曲角 |
[编辑] 返回值
如果没有错误发生,则返回arg
的双曲余弦 (cosh(arg),或 earg +e-arg |
2 |
如果发生溢出的范围错误,则返回 +HUGE_VAL、+HUGE_VALF
或 +HUGE_VALL
。
[编辑] 错误处理
错误按照 math_errhandling
中的规定报告。
如果实现支持 IEEE 浮点算术 (IEC 60559),
- 如果参数为 ±0,则返回 1
- 如果参数为 ±∞,则返回 +∞
- 如果参数为 NaN,则返回 NaN
[编辑] 注解
对于 IEEE 兼容类型 double,如果 |arg| > 710.5,则 cosh(arg)
会溢出。
[编辑] 范例
运行此代码
#include <errno.h> #include <fenv.h> #include <math.h> #include <stdio.h> // #pragma STDC FENV_ACCESS ON int main(void) { printf("cosh(1) = %f\ncosh(-1)= %f\n", cosh(1), cosh(-1)); printf("log(sinh(1) + cosh(1))=%f\n", log(sinh(1) + cosh(1))); // special values printf("cosh(+0) = %f\ncosh(-0) = %f\n", cosh(0.0), cosh(-0.0)); // error handling errno = 0; feclearexcept(FE_ALL_EXCEPT); printf("cosh(710.5) = %f\n", cosh(710.5)); if (errno == ERANGE) perror(" errno == ERANGE"); if (fetestexcept(FE_OVERFLOW)) puts(" FE_OVERFLOW raised"); }
可能的输出
cosh(1) = 1.543081 cosh(-1)= 1.543081 log(sinh(1) + cosh(1))=1.000000 cosh(+0) = 1.000000 cosh(-0) = 1.000000 cosh(710.5) = inf errno == ERANGE: Numerical result out of range FE_OVERFLOW raised
[编辑] 参考文献
- C23 标准 (ISO/IEC 9899:2024)
- 7.12.5.4 The cosh functions (p: TBD)
- 7.25 Type-generic math <tgmath.h> (p: TBD)
- F.10.2.4 The cosh functions (p: TBD)
- C17 标准 (ISO/IEC 9899:2018)
- 7.12.5.4 The cosh functions (p: 176)
- 7.25 Type-generic math <tgmath.h> (p: 272-273)
- F.10.2.4 The cosh functions (p: 379)
- C11 标准 (ISO/IEC 9899:2011)
- 7.12.5.4 The cosh functions (p: 241)
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
- F.10.2.4 The cosh functions (p: 520)
- C99 标准 (ISO/IEC 9899:1999)
- 7.12.5.4 The cosh functions (p: 222)
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
- F.9.2.4 The cosh functions (p: 457)
- C89/C90 标准 (ISO/IEC 9899:1990)
- 4.5.3.1 The cosh function
[编辑] 参见
(C99)(C99) |
计算双曲正弦 (sinh(x)) (函数) |
(C99)(C99) |
计算双曲正切 (tanh(x)) (函数) |
(C99)(C99)(C99) |
计算反双曲余弦 (arcosh(x)) (函数) |
(C99)(C99)(C99) |
计算复双曲余弦 (函数) |
C++ 文档 关于 cosh
|