C
数值 | Numerics

cosh

cosh, coshf, coshl

在头文件中定义
float coshf( float arg (1)(since C99)
double cosh( double arg (2)
long double coshl( long double arg (3)(since C99)
Defined in header <tgmath.h>
#define cosh( arg )(4)(since C99)

1-3)计算双曲余弦arg

4)类型 - 通用宏:如果参数具有类型long doublecoshl则被调用。否则,如果参数具有整数类型或类型doublecosh则调用该参数。否则,coshf被调用。如果参数是复杂的,则宏调用相应的复变函数(ccoshfccoshccoshl)。

参数

arg-浮点值代表双曲线角度

返回值

如果没有错误发生,则arg(cosh(arg)或。的双曲余弦

| earg+e-arg |

|:----|

| 2 |

)返回。

如果范围误差由于发生溢出,+HUGE_VAL+HUGE_VALF,或+HUGE_VALL返回。

错误处理

按照math_errhandling中的指定报告错误。

如果实现支持IEEE浮点运算(IEC 60559),

  • 如果参数为±0,则返回1

笔记

对于IEEE兼容类型double,如果| arg | > 710.5,然后cosh(arg)溢出。

#include <stdio.h> #include <math.h> #include <errno.h> #include <fenv.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

参考

  • C11标准(ISO / IEC 9899:2011):