English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Reference Manual

C++ Library Function <cmath>

C ++asin() Function Usage and Example

This function returns the arcsine of a number in radians form.<cmath>defined in the header file.

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

asin() Prototype [From C ++ 11Standard Start]

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

asin() parameters

The asin() function uses[-1,1]is a single required parameter within the range.

This is because the sine value in1to-1is within the range.

The return value of asin()

Assuming the parameter is in [-1,1within the range, then the asin() function returns[-π/ 2, π/ 2]values within the range.

If the parameter is greater than1or less-1, then asin() returns NaN, which is not a number.

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

Example1How does asin() work?

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  double x = 0.25, result;
  result = asin(x);
  
  cout << "asin(x) = " << result << " radians" << endl;
  cout << "asin(x) = " << result*180/3.1415 << "degrees" << endl;
  
  return 0;
}

When the program is run, the output is:

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

Example2: The asin() function with integer 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;
  //Convert the result to degrees
  cout << "asin(x) = " << result*180/PI << " degrees";
  
  return 0;
}

When the program is run, the output is:

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

  C++ Library Function <cmath>