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时。

链接: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=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的值等于零时。

#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()函数计算数字的反余弦值。

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

技术教程推荐

玩转webpack -〔程柳锋〕

说透中台 -〔王健〕

Kafka核心源码解读 -〔胡夕〕

To B市场品牌实战课 -〔曹林〕

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

爱上跑步 -〔钱亮〕

如何落地业务建模 -〔徐昊〕

商业思维案例笔记 -〔曹雄峰〕

AI大模型系统实战 -〔Tyler〕

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