📜  C++ asin()

📅  最后修改于: 2020-09-25 07:21:11             🧑  作者: Mango

C++中的asin() 函数以弧度返回数字的反正弦值。

此函数在头文件中定义。

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

asin()原型[从C++ 11标准开始]

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

asin()参数

asin() 函数采用[-1,1]范围内的单个必需参数。

这是因为正弦值在1到-1的范围内。

asin()返回值

假设参数在[-1,1]范围内,则asin() 函数返回在[-π/ 2,π/ 2]范围内的值。

如果参数大于1或小于-1,则asin()返回NaN即不是数字。

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

示例1:asin()如何工作?

#include 
#include 

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;
}

运行该程序时,输出为:

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

示例2:具有整数类型的asin() 函数

#include 
#include 
#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;
}

运行该程序时,输出为:

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