C acosh()

acosh() 函数接受一个参数 (x ≥ 1),并以弧度为单位返回反双曲余弦值。在数学上,acosh(x) = cosh-1(x)

acosh() 函数包含在 <math.h> 头文件中。


acosh() 原型

double acosh(double x);

要查找类型为 intfloatlong double 的反双曲余弦值,可以使用强制类型转换运算符显式将类型转换为 double

 int x = 0;
 double result;
 result = acosh(double(x));

此外,C99 中引入了两个函数 acoshf() 和 acoshl(),它们分别专门用于处理 floatlong double 类型。

float acoshf(float x);
long double acoshl(long double x);

acosh() 参数和返回值

acosh() 函数接受一个大于或等于 1 的参数。

参数 描述
double 值 必需。一个大于或等于 1 的 double 值  (x ≥ 1)。

acosh() 返回值

acosh() 函数以弧度为单位返回一个大于或等于 0 的数字。如果传入的参数小于 1 ( x < 1),则函数返回 NaN (非数字)。

参数 (x) 返回值
x ≥ 1 一个大于或等于 0 的数字 (以弧度为单位)
x < 1 NaN (非数字)

示例 1:不同参数的 acosh() 函数

#include <stdio.h>
#include <math.h>

int main()
{
    // constant PI is defined
    const double PI =  3.1415926;
    double x, result;

    x =  5.9;
    result = acosh(x);
    printf("acosh(%.2f) = %.2lf in radians\n", x, result);

    // converting radians to degree
    result = acosh(x)*180/PI;
    printf("acosh(%.2f) = %.2lf in degrees\n", x, result);

    // parameter not in range
    x = 0.5;
    result = acosh(x);
    printf("acosh(%.2f) = %.2lf", x, result);

    return 0;
}

输出

acosh(5.90) = 2.46 in radians
acosh(5.90) = 141.00 in degrees
acosh(0.50) = nan

示例 2:INFINITY 和 DBL_MAX 的 acosh()

#include <stdio.h>
#include <math.h>
#include <float.h>

int main()
{
    double x, result;

    // maximum representable finite floating-point number
    x =  DBL_MAX;
    result = acosh(x);
    printf("Maximum value of acosh() in radians = %.3lf\n", result);

    // Infinity
    x = INFINITY;
    result = acosh(x);
    printf("When infinity is passed to acosh(), result = %.3lf\n", result);

    return 0;
}

可能的输出

Maximum value of acosh() in radians = 710.476
When infinity is passed to acosh(), result = inf

在此,定义在 float.h 头文件中的 DBL_MAX 是可表示的最大有限浮点数。而定义在 math.h 中的 INFINITY 是表示正无穷的常量表达式。

示例 3:acoshf() 和 acoshl() 函数

#include <stdio.h>
#include <math.h>
int main()
{
    float fx, facosx;
    long double lx, ldacosx;

    // arc hyperbolic cosine of type float
    fx = 5.5054;
    facosx = acoshf(fx);

    // arc hyperbolic cosine of type long double
    lx = 5.50540593;
    ldacosx = acoshl(lx);

    printf("acoshf(x) = %f in radians\n", facosx);
    printf("acoshl(x) = %Lf in radians", ldacosx);

    return 0;
}

输出

acoshf(x) = 2.390524 in radians
acoshl(x) = 2.390525 in radians
你觉得这篇文章有帮助吗?

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战