C atanh()

atanh() 函数在 math.h 头文件中定义。它有助于返回给定数字的反双曲正切值(以弧度表示)。反双曲正切表示反双曲正切值。


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

此外,还使用了 atanhf() 和 atanhl() 两个函数,分别用于 float 和 long double 类型。


float atanhf(float x); 
long double atanhl(long double x); 

atanh() 参数

atanh() 函数接受一个在范围 (-1 ≤ x ≥ 1) 内的单个参数。使用强制转换运算符,我们可以将类型显式转换为 double,以查找 int、float 或 long double 类型的反双曲正切。

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

atanh() 返回值

atanh() 函数的返回值是一个在 [-pi/2, +pi/2] 弧度区间内的数字。

输入 返回值
-1 ≤ x ≥ 1 [-pi/2, +pi/2] 弧度
-1 > x NaN (非数字)

atanh() 示例

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


#include <stdio.h>
#include <math.h>
int main()
{

    const double PI =  3.1415926;
    double v, output;

    v =  -0.5;
    output = atanh(v);
    printf("The atanh(%.2f) is equal to %.2lf in radians\n", v, output);

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

    // parameter not in range
    v = 3;
    output = atanh(v);
    printf("The atanh(%.2f) is equal to %.2lf", v, output);

    return 0;
}

输出


The atanh(-0.50) is equal to -0.55 in radians
The atanh(-0.50) is equal to -31.47 in degrees
The atanh(3.00) is equal to nan
 

示例 2:C 语言中 atanh() 的工作原理?


#include <stdio.h>
#include <math.h>
int main (){
  printf("%lf\n", atanh(0.1));
  printf("%lf\n", atanh(0.5));
  printf("%lf\n", atanh(2));
  return 0;
}

输出


0.100335
0.549306
-nan