📅  最后修改于: 2020-09-25 07:19:46             🧑  作者: Mango
此函数在
[Mathematics] cos-1x = acos(x) [In C++ Programming];
double acos(double x);
float acos(float x);
long double acos(long double x);
double acos (T x); // For integral type
acos() 函数采用[-1,1]范围内的单个必需参数。这是因为余弦值在1到-1的范围内。
假定参数在[-1,1]范围内,则acos() 函数返回在[0,π]范围内的值。
如果参数大于1或小于-1,则acos()返回NaN
即不是数字。
Parameter (x) | Return Value |
---|---|
x = [-1, 1] | [0, π] in radians |
-1 > x or x > 1 | NaN (Not a Number) |
#include
#include
using namespace std;
int main()
{
double x = 0.0, result;
result = acos(x);
cout << "acos(x) = " << result << " radians" << endl;
// result in degrees
cout << "acos(x) = " << result*180/3.1415 << " degrees" << endl;
return 0;
}
运行该程序时,输出为:
acos(x) = 1.5708 radians
acos(x) = 90.0027 degrees
#include
#include
using namespace std;
int main()
{
int x = -1;
double result;
result = acos(x);
cout << "acos(x) = " << result << " radians" << endl;
// Converting result to degrees
cout << "acos(x) = " << result*180/3.1415 << " degrees";
return 0;
}
运行该程序时,输出为:
acos(x) = 3.14159 radians
acos(x) = 180.005 degrees