cosh, coshf, coshl
From cppreference.net
Common mathematical functions
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<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 | - | 表示双曲角的浮点值 |
返回值
If no errors occur, the hyperbolic cosine of
arg
(
cosh(arg)
, or
|
e
arg
+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))); // 特殊值 printf("cosh(+0) = %f\ncosh(-0) = %f\n", cosh(0.0), cosh(-0.0)); // 错误处理 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函数(页码:222)
-
- 7.22 泛型数学 <tgmath.h>(页码:335-337)
-
- F.9.2.4 cosh函数(页码:457)
- C89/C90 标准 (ISO/IEC 9899:1990):
-
- 4.5.3.1 cosh 函数
参考
|
(C99)
(C99)
|
计算双曲正弦函数 (
\({\small\sinh{x} }\)
sinh(x)
)
(函数) |
|
(C99)
(C99)
|
计算双曲正切函数 (
\({\small\tanh{x} }\)
tanh(x)
)
(函数) |
|
(C99)
(C99)
(C99)
|
计算反双曲余弦函数 (
\({\small\operatorname{arcosh}{x} }\)
arcosh(x)
)
(函数) |
|
(C99)
(C99)
(C99)
|
计算复数双曲余弦函数
(函数) |
|
C++ 文档
关于
cosh
|
|