asin函数头文件c++
C ++ asin()函数 (C++ asin() function)
asin() function is a library function of cmath header, it is used to find the principal value of the arc sine of the given number, it accepts a number (x) and returns the principal value of the arc sine of x in radians.
asin()函数是cmath标头的库函数,用于查找给定数字反正弦的主值,它接受数字( x )并以弧度返回x的反正弦的主值。
Note: Value (x) must be between -1 to +1, else it will return a domain error (nan).
注意:值( x )必须介于-1到+1之间,否则它将返回域错误( nan )。
Syntax of asin() function:
asin()函数的语法:
asin(x);
Parameter(s): x – is the value whose arc sine to be calculated.
参数: x –是要计算其反正弦值的值。
Return value: double – it returns double type value that is the principal value of the arc sine of the given number x.
返回值: double-返回double类型的值,它是给定数字x的反正弦值的主要值。
Example:
例:
Input:
float x = 0.65;
Function call:
asin(x);
Output:
0.707584
C ++代码演示asin()函数的示例 (C++ code to demonstrate the example of asin() function)
// C++ code to demonstrate the example of
// asin() function
#include <iostream>
#include <cmath>
using namespace std;
// main() section
int main()
{
float x;
x = -1.0;
cout<<"asin("<<x<<"): "<<asin(x)<<endl;
x = -0.89;
cout<<"asin("<<x<<"): "<<asin(x)<<endl;
x = 0.65;
cout<<"asin("<<x<<"): "<<asin(x)<<endl;
x = 1;
cout<<"asin("<<x<<"): "<<asin(x)<<endl;
return 0;
}
Output
输出量
asin(-1): -1.5708
asin(-0.89): -1.09735
asin(0.65): 0.707584
asin(1): 1.5708
Example with domain error
域错误示例
If we provide the value out of the range (except -1 to +1), it returns nan.
如果我们提供的值超出范围(-1到+1除外),它将返回nan 。
// C++ code to demonstrate the example of
// asin() function
#include <iostream>
#include <cmath>
using namespace std;
// main() section
int main()
{
float x;
x = -0.89; //no error
cout<<"asin("<<x<<"): "<<asin(x)<<endl;
x = 2.65; //error
cout<<"asin("<<x<<"): "<<asin(x)<<endl;
x = -1.25; //error
cout<<"asin("<<x<<"): "<<asin(x)<<endl;
return 0;
}
Output
输出量
asin(-0.89): -1.09735
asin(2.65): nan
asin(-1.25): nan
Reference: C++ asin() function
参考: C ++ asin()函数
翻译自: https://www.includehelp.com/cpp-tutorial/asin-function-with-example.aspx
asin函数头文件c++