C 语言 asin()

asin() 函数在 math.h 头文件中定义。它有助于返回给定数字的弧度制反正弦值。反正弦表示 反正弦值。


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

此外,还使用了 asinf() 和 asinl() 两个函数,分别对应 float 和 long double 类型。


float asinf(float x); 
long double asinl(long double x); 

asin() 参数

asin() 函数接受一个介于 1 ≥ x ≥ -1 之间的单个参数。我们可以使用类型转换运算符将类型显式转换为 double,以查找 int、float 或 long double 类型的反正弦。

参数 描述 必需/可选
双精度浮点数值 一个介于 -1 和 +1 之间的双精度值 必需

asin() 返回值

asin() 函数的返回值范围在 [-π/2, +π/2] 弧度之间。

输入 返回值
x = [-1, +1] [-π/2, +π/2] 弧度
-1 > x 或 x > 1 NaN (非数字)

asin() 示例

示例 1:C 语言中 asin() 函数的用法?


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

    v =  -0.5;
    output = asin(v);
    printf("The Inverse of sin(%.2f) = %.2lf in radians\n", v, output);

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

    // paramter not in range
    v = 1.2;
    output = asin(v);
    printf("The Inverse of sin(%.2f) = %.2lf", v, output);

    return 0;
}

输出


The Inverse of sin(-0.50) = -0.52 in radians
The Inverse of sin(-0.50) = -30.00 in degrees
the Inverse of sin(1.20) = nan

示例 2:asinf() 和 asinl() 函数在 C 语言中如何工作?


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

    // type float
    f = -0.505405;
    fsinx = asinf(f);

    //type long double
    l = -0.50540593;
    lsinx = asinl(l);

    printf("asinf(x) is equal to %f in radians\n", fsinx);
    printf("asinl(x) is equal to %Lf in radians", lsinx);

    return 0;
}

输出


asinf(x) is equal to -0.529851 in radians
asinl(x) is equal to -0.529852 in radians