C++ asin()

This function is defined in <cmath> header file.


[Mathematics] sin-1x = asin(x) [In C++ Programming];

asin() prototype [As of C++ 11 standard]

double asin(double x);
float asin(float x);
long double asin(long double x);
double asin (T x);

asin() Parameters

The asin() function takes a single mandatory argument in the range [-1, 1].

It is because the value of sine is in the range of 1 and -1.


asin() Return value

Given that the argument is in the range [-1, 1], the asin() function returns the value in the range of [-π/2, π/2].

If the argument is greater than 1 or less than -1, asin() returns NaN i.e. not a number.


Parameter (x) Return Value
x = [-1, 1] [-π/, π/2] in radians
-1 > x or x > 1 NaN (Not a Number)

Example 1: How asin() works?

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
  double x = 0.25, result;
  result = asin(x);
  
  cout << "asin(x) = " << result << " radians" << endl;
  // result in degrees
  cout << "asin(x) = " << result*180/3.1415 << " degrees" << endl;
  
  return 0;
}

When you run the program, the output will be:

asin(x) = 0.25268 radians
asin(x) = 14.4779 degrees

Example 2: asin() function with integral type

#include <iostream>
#include <cmath>
#define PI 3.141592654

using namespace std;

int main()
{
  int x = 1;
  double result;
  
  result = asin(x);
  
  cout << "asin(x) = " << result << " radians" << endl;
  // Converting result to degrees
  cout << "asin(x) = " << result*180/PI << " degrees";
  
  return 0;
}

When you run the program, the output will be:

asin(x) = 1.5708 radians
asin(x) = 90 degrees 

Also Read:

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges