C asin()

The asin() function defined in the math.h header file. It helps to return the arc sine value of the given number in radians. The arc sine means inverse sine value.


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

Also, two functions asinf() and asinl() were used with type float and long double respectively.


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

asin() Parameters:

The asin() function takes a single parameter between the range 1 ≥ x ≥ -1. Using cast operator we can explicitly convert the type to double to find the arc sine of type int, float, or long double.

Parameter Description Required / Optional
double value A double value between - 1 and +1 Required

asin() Return Value

The return value of asin() function is in the range of [-π/2, +π/2]  in radians.

Input Return Value
x = [-1, +1] [-π/2, +π/2] in radians
-1 > x or x > 1 NaN (not a number)

Examples of asin()

Example 1: Working of asin() function in C?


#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;
}

Output:


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

Example 2: How asinf() and asinl() functions worked in 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;
}

Output:


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