# C++ cmath asin , asinf and asinl function

The C++ cmath asin, asinf and asinl function compute the arc sine of the given value.The declaration of the functions 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);

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).

Link: C++ nan

Code example

#include <typeinfo>

cout<< asine(0.12) << endl
<< asine(1);

cout<< typeid( asine(0.12) ).name( ) ;

Output

0.12029
0
d (means ‘double’)

Here is another code example that check the return value when the argument does not belong to the specified interval.

cout<< asine(1.1) << endl
<< asin( -1.1) ;

Output

nan
nan

#### asinf and asinl

asinf function

The asinf function is same as the 1st asin function.Note the character ‘f’ is appended in asinf to signify the float type of the argument and the return value.

Code example

float f=0.2;

cout<< asin(f) << endl
<< asinf(0.2) << endl ;

cout<< typeid( asin(f) ).name( ) << endl
<< typeid( asinf(0.2) ).name( ) << endl ;

cout<< asinf( 1.1) ;

Output

0.201358
0.201358
f
f
nan

The return type is float in asinf and asin(float).

acosl function

The asinl output the same value as any other asin function.But the return type is long double so it is similar to the 3rd overloaded version:long double asinl(long double).

Code example

long double ld=0.22 ;

cout<< asin(ld) << endl
<< asinl(0.22) << endl ;

cout<< typeid( asin(ld) ).name( ) << endl
<< typeid( asinl(0.22) ).name( ) << endl ;

cout<< asinl(2.3) ;

Output

0.221814
0.221814
e (means ‘long double’)
e (means ‘long double’)
nan

#### Getting degree instead of radian with asin

The returned value of asin is measure in radian.We can however convert this radian value to degree if the need ever arises using a simple conversion rule.

The relation between radian and degree is shown below,

1 radian = (180/3.141592) degree

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

Code example

cout<< “asin(0.5°)=” << ( asin(0.5)*180 )/3.141592 << “°” << endl ;

Output

asin(0.5)=30°