C ++中的asin()函數(shù)以弧度形式返回?cái)?shù)字的反正弦值。
此函數(shù)在<cmath>頭文件中定義。
[Mathematics] sin-1x = asin(x) [C++];
double asin(double x); float asin(float x); long double asin(long double x); double asin (T x);
asin()函數(shù)采用[-1,1]范圍內(nèi)的單個(gè)必需參數(shù)。
這是因?yàn)檎抑翟?到-1的范圍內(nèi)。
假設(shè)參數(shù)在[-1,1]范圍內(nèi),則asin()函數(shù)返回[-π/ 2,π/ 2]范圍內(nèi)的值。
如果參數(shù)大于1或小于-1,則asin()返回,NaN即不是數(shù)字。
參數(shù)(x) | 返回值 |
---|---|
x = [-1,1] | [-π/,π/ 2]以弧度為單位 |
-1> x或x> 1 | NaN(非數(shù)字) |
#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; }
運(yùn)行該程序時(shí),輸出為:
asin(x) = 0.25268 radians asin(x) = 14.4779 degrees
#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; //將結(jié)果轉(zhuǎn)換為角度 cout << "asin(x) = " << result*180/PI << " degrees"; return 0; }
運(yùn)行該程序時(shí),輸出為:
asin(x) = 1.5708 radians asin(x) = 90 degrees