C acosh()

acosh() 函数定义在 math.h 头文件中。它用于返回给定数字的反双曲余弦值,单位为弧度。反双曲余弦值意味着反双曲余弦值。


double acosh(double x); #where x can be in int, float or long double

此外,acoshf() 和 acoshl() 函数分别用于 float 和 long double 类型。


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

acosh() 参数

acosh() 函数接受一个参数,其范围为 x ≥ 1。我们可以使用强制转换运算符将 int、float 或 long double 类型显式转换为 double 类型,以求其反双曲余弦值。

参数 描述 必需/可选
双精度浮点数值 一个大于或等于 1 的双精度值 (x ≥ 1) 必需

acosh() 返回值

acosh() 函数的返回值是一个大于或等于 0 的弧度值。

输入 返回值
x ≥ 1 一个大于或等于 0 的数字
x < 1 NaN (非数字)

acosh() 示例

示例 1:acosh() 函数在 C 语言中的工作原理?


#include <stdio.h>
#include <math.h>
int main()
{
    
    const double PI =  3.1415926;
    double v, output;

    v =  5.9;
    output = acosh(v);
    printf("The acosh(%.2f) = %.2lf in radians\n", v, output);

    //radians to degree convertion
    output = acosh(v)*180/PI;
    printf("The acosh(%.2f) = %.2lf in degrees\n", v, output);

    // paramter not in range
    v = 0.5;
    output = acosh(v);
    printf("The acosh(%.2f) = %.2lf", v, output);

    return 0;
}

输出


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

示例 2:acoshf() 和 acoshl() 函数在 C 语言中的工作原理?


#include <stdio.h>
#include <math.h>
int main()
{
    float f, fcosx;
    long double l, lcosx;

    // type float
    f = 5.5054;
    fcosx = acoshf(f);

    //type long double
    l = 5.50540593;
    lcosx = acoshl(l);

    printf("acoshf(x) is equal to %f in radians\n", fcosx);
    printf("acoshl(x) is equal to %Lf in radians", lcosx);

    return 0;
}

输出


acoshf(x) is equal to 2.390524 in radians
acoshl(x) is equal to 2.390525 in radians