The built-in function asin()
can be accessed using the cmath
header file. It is used to calculate the inverse sine value of the parameter provided in radians. This is depicted in the diagram below:
The permitted values of the parameter (x
) are from -1
to 1
(inclusive). This is due to the sine function having a range of -1
to 1
.
The return value, i.e., the range of asin( )
is from -π/2
to π/2
(in radians).
The asin()
function can be provided inputs of the following types:
int
double
float
long double
The return data type for the aforementioned input data types are:
double asin(double x)float asin(float x)double asin(int x)long double asin(long double)
x
within range (between 1 and -1)#include <iostream>#include <cmath>using namespace std;int main() {double x = 0.5;double answer = asin(x);cout << "The answer in radians is: " << answer << endl;cout << "The answer in degrees is: " << (answer * 180)/3.142 << endl; //converting radians to degreesreturn 0;}
When the parameter value is within the specified domain, the code executes normally.
x
out of range (greater than 1 or less than -1)#include <iostream>#include <cmath>using namespace std;int main() {double x = -2;double answer = asin(x);cout << "The answer in radians is: " << answer << endl;cout << "The answer in degrees is: " << (answer * 180)/3.142 << endl; //converting radians to degreesreturn 0;}
When x
is not between -1 and 1, the output is nan
, i.e., Not a Number. This occurs due to a domain error, where the input value is invalid because it is beyond the allowed values of a function. This results in an undefined expression.
Free Resources