acos(x)函数详解

首页 / C++入门教程 / acos(x)函数详解

此函数计算弧度中数字的反余弦值。

acos(x) = cos -1x

acos - 语法

假设数字是x。语法为:

无涯教程网

float acos(float x);
double acos(double x);
long double acos(long double x);
double acos(integral x);

Note: 如果传递的值是整数类型,则将其强制转换为double。

acos - 参数

x :要计算其反余弦的值。它应该在[-1,1]范围内。

acos - 返回值

参数 返回值
-1≤x≤1 (0,∏)
x1 Not a number

acos - 例子1

让我们看一个简单的例子,当x的值大于1时。

#include <iostream>  
#include<math.h>  
using namespace std;  
int main()  
{  
    float degree=90;  
    float x=degree*3.14/180;  
    std::cout << "Value of cosine is :" <<cos(x)<< std::endl;  
    cout<<"Inverse of cosine is :"<<acos(x);  
    return 0;  
}  

输出:

Value of cosine is :0.000796274
Inverse of cosine is :nan   

在此示例中,当x的值大于1时,acos()函数计算数字的反余弦值。

acos - 例子2

让我们看一个简单的例子,当x的值等于零时。

链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-acos-function.html

来源:LearnFk无涯教程网

#include <iostream>  
#include<math.h>  
using namespace std;  
int main()  
{  
    float degree=0;  
    float x=degree*3.14/180;  
    std::cout << "Value of cosine is :" <<cos(x)<< std::endl;  
    cout<<"Inverse of cosine is :"<<acos(x);  
    return 0;  
}  

输出:

Value of cosine is :1
Inverse of cosine is :1.5708   

在此示例中,当x的值等于零时,acos()函数计算数字的反余弦值。

acos - 例子3

让我们看一个简单的例子,当x小于-1时。

#include <iostream>  
#include<math.h>  
using namespace std;  
int main()  
{  
    float degree= -60;  
    float x=degree*3.14/180;  
    std::cout << "Value of cosine is :" <<cos(x)<< std::endl;  
    cout<<"Inverse of cosine is :"<<acos(x);  
    return 0;  
}  

输出:

Value of cosine is :0.50046
Inverse of cosine is :nan   

在此示例中,当x的值小于-1时,acos()函数计算数字的反余弦值。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

AI技术内参 -〔洪亮劼〕

程序员的数学基础课 -〔黄申〕

重学前端 -〔程劭非(winter)〕

编译原理之美 -〔宫文学〕

Linux内核技术实战课 -〔邵亚方〕

Flink核心技术与实战 -〔张利兵〕

结构写作力 -〔李忠秋〕

给程序员的写作课 -〔高磊〕

云原生基础架构实战课 -〔潘野〕

好记忆不如烂笔头。留下您的足迹吧 :)