C programming math.h asin , asinf and asinl


In C programming the <math.h> asin ,asinf and asinl function compute the arc sine of the argument.The declaration of the function is given below.

1 float asin(float x);
2 double asin(double x);
3 long double asin(long double x);
4 float asinf(float x);
5 long double asinl(long double x);

Parameters:
x -A floating point value.

Return type
floating point value -The arc sine of the argument passed.

All the functions are the same,they compute the arc cosine of the argument.The 1st,2nd and the 3rd function have the same name i.e. ‘asin’.The 4th and 5th function have different names.What does having a different names means is explained in detail below.

Some points to note:

i-i-The argument ‘x’ should be in the interval [-1,1].If the argument is not in the said interval a domain error occurs and so ‘nan‘ is returned.

ii-The returned value is in the interval [-π/2,+π/2] radians.

iii-The second version is the default version that is called when asin is called in our program.

iv-When the argument passed is int type the default version is called.

Note arc sine means inverse of sine,so asin(x) is same as sin-1(x).

Code example

double d1 = 0.12, d2 = 12;

float f1 = 0.345;

long double ld = 0.555 ;

printf(“%lf”, asin( d1 ) ) ; //calls the 2nd version
printf(“\n%f”, asin( f1 ) ) ; //calls the 1st version
printf(“\n%Lf”, asin(ld) ) ; //calls the 3rd version

printf(“\n%lf”, asin(d2) ) ;
printf(“\n%lf”, asin(INFINITY) ) ;

Output in Visual Studio,

0.120290
0.352239
0.588363
-nan(ind)
-nan(ind)

The ‘-nan(ind)’ means the computed value is not representable or it simply stands for NaN.






asinf

The ‘asinf‘ function is same as the 1st function.This means the parameter and return type of the function is float type.The ‘f‘ character appended to ‘asinf‘ stands for float and it signify the parameter and return type of the function.

Code example

float f = 0.77 ;

printf(“%f”, asin( f ) ) ; //Calls the 1st version
printf(“\n%f”, asinf( 0.77 ) ) ; //same as above

Output,

0.878841
0.878841


asinl

The ‘asinl‘ function is same as the 3rd function.This means the parameter and return type of the function is long double type.The ‘l‘ character appended to ‘asinl‘ stands for long double and it signify the parameter and return type of the function.

Code example

long double ld = 0.671 ;

printf(“%Lf”, asin( ld ) ) ; //Call the 3rd version
printf(“\n%Lf”, asinl( 0.671 ) ) ; //same as above

Output,

0.735557
0.735557


 


Getting degree instead of radian with asin

The C asin, asinf and asinl return the value in radian,to get the value as degree apply the simply operation given below.

Now,

1 radian = (180/3.141592) degree

So multiplying the output value with (180/3.141592) will change the value to degree type.

Code example

printf(“asinl(0.345)=%lf%c”, asinl( 0.345 ) , (int)248 );

Output

asin(0.345)=20.181800°

The character of the integer value 248 is ‘°’-the degree sign.