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 cosh 函数 (p: TBD)
- 7.25 类型通用数学 <tgmath.h> (p: TBD)
- F.10.2.4 cosh 函数 (p: TBD)
- C17 标准 (ISO/IEC 9899:2018)
- 7.12.5.4 cosh 函数 (p: 176)
- 7.25 类型通用数学 <tgmath.h> (p: 272-273)
- F.10.2.4 cosh 函数 (p: 379)
- C11 标准 (ISO/IEC 9899:2011)
- 7.12.5.4 cosh 函数 (p: 241)
- 7.25 类型通用数学 <tgmath.h> (p: 373-375)
- F.10.2.4 cosh 函数 (p: 520)
- C99 标准 (ISO/IEC 9899:1999)
- 7.12.5.4 cosh 函数 (p: 222)
- 7.22 类型通用数学 <tgmath.h> (p: 335-337)
- F.9.2.4 cosh 函数 (p: 457)
- C89/C90 标准 (ISO/IEC 9899:1990)
- 4.5.3.1 cosh 函数
[编辑] 另请参阅
(C99)(C99) |
计算双曲正弦 (sinh(x)) (函数) |
(C99)(C99) |
计算双曲正切 (tanh(x)) (函数) |
(C99)(C99)(C99) |
计算反双曲余弦 (arcosh(x)) (函数) |
(C99)(C99)(C99) |
计算复双曲余弦 (函数) |
C++ 文档 for cosh
|