C++ asin() 函数
asin() 函数是 cmath 头文件的库函数,用于求给定数的反正弦的主值,它接受一个数 (x
) 并返回反正弦的主值x
以弧度表示。
注意:价值 (x
) 必须介于 -1 到 +1 之间,否则将返回域错误 (nan
)。
asin() 函数的语法:
asin(x);
参数: x
– 是要计算其反正弦的值。
返回值: double
– 它返回 double 类型的值,它是给定数字的反正弦的主值x
。
例:
Input: float x = 0.65; Function call: asin(x); Output: 0.707584
C++代码演示asin()函数的例子
// 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;
}
输出
asin(-1):-1.5708 asin(-0.89):-1.09735 asin(0.65):0.707584 asin(1):1.5708
域错误示例
如果我们提供的值超出范围(-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;
}
输出
asin(-0.89):-1.09735 asin(2.65):nan asin(-1.25):nan
参考:C++ asin() 函数
相关用法
- C++ complex asin()用法及代码示例
- C++ asinh()用法及代码示例
- C++ complex asinh()用法及代码示例
- C++ asctime()用法及代码示例
- C++ atexit()用法及代码示例
- C++ any_of()用法及代码示例
- C++ acos()用法及代码示例
- C++ atof()用法及代码示例
- C++ abort()用法及代码示例
- C++ atol()用法及代码示例
- C++ complex acosh()用法及代码示例
- C++ array at()用法及代码示例
- C++ complex atanh()用法及代码示例
- C++ array::fill()、array::swap()用法及代码示例
- C++ array::operator[]用法及代码示例
- C++ atoll()用法及代码示例
- C++ array::size()用法及代码示例
- C++ array::rbegin()、array::rend()用法及代码示例
- C++ atan()用法及代码示例
- C++ complex abs()用法及代码示例
注:本文由纯净天空筛选整理自 asin() function with example in C++。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。