cosh() 函数在 math.h 头文件中定义。它有助于返回给定数字的弧度双曲余弦值。
double cosh( double x ); #where x should be in double
此外,还使用了两个函数 coshf() 和 coshl(),分别用于浮点型和长双精度型。
float coshf(float x);
long double coshl(long double x);
cosh() 函数接受一个参数。使用强制转换运算符,我们可以显式地将类型转换为双精度浮点型,以查找整数、浮点数或长双精度数的双曲余弦值。
| 参数 | 描述 | 必需/可选 |
|---|---|---|
| 双精度浮点数值 | 任何从负到正的 double 值 | 必需 |
cosh() 函数的返回值为弧度双精度浮点型。
| 输入 | 返回值 |
|---|---|
| 从负数到正数的任意值 | 以弧度表示的双精度值 |
#include <stdio.h>
#include <math.h>
int main()
{
double v, output;
v = 0.5;
output = cosh(v);
printf("The Hyperbolic cosine of %lf (in radians) is %lf\n", v, output);
v = -0.5;
output = cosh(v);
printf("The Hyperbolic cosine of %lf (in radians) is %lf\n", v, output);
v = 0;
output = cosh(v);
printf("The Hyperbolic cosine of %lf (in radians) is %lf\n", v, output);
v = 1.5;
output = cosh(v);
printf("The Hyperbolic cosine of %lf (in radians) is %lf\n", v, output);
return 0;
}
输出
The Hyperbolic cosine of 0.500000 (in radians) is 1.127626 The Hyperbolic cosine of -0.500000 (in radians) is 1.127626 The Hyperbolic cosine of 0.000000 (in radians) is 1.000000 The Hyperbolic cosine of 1.500000 (in radians) is 2.352410
#include <stdio.h>
#include <math.h>
int main () {
double v;
v = 1.0;
printf("The hyperbolic cosine of %lf is %lf\n", v, cosh(v));
return(0);
}
输出
The hyperbolic cosine of 1.000000 is 1.543081