asin函数头文件c++_asin()函数以及C ++中的示例

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++

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值