此函數以弧度計算數字的反餘弦值。
acos(x) = cos-1x
用法
假設一個數字是 x。語法是:
float acos(float x);
double acos(double x);
long double acos(long double x);
double acos(integral x);
注意:如果傳遞的值是整數類型,則將其強製轉換為 double。
參數
x:要計算其反餘弦值的值。它應該在[-1,1]範圍內。
返回值
參數 | 返回值 |
---|---|
-1≤x≤1 | (0,∏) |
x1 | 不是數字 |
例子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
在本例中,acos() 函數計算 x 大於 1 時數字的反餘弦值。
例子2
讓我們看一個簡單的例子,當 x 的值等於 0 時。
#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
在本例中,acos() 函數計算當 x 的值等於 0 時數字的反餘弦值。
例子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() 函數計算一個數的反餘弦值。
相關用法
- C++ Math acosh()用法及代碼示例
- C++ Math asinh()用法及代碼示例
- C++ Math atan()用法及代碼示例
- C++ Math asin()用法及代碼示例
- C++ Math atan2()用法及代碼示例
- C++ Math abs()用法及代碼示例
- C++ Math atanh()用法及代碼示例
- C++ Math scalbn()用法及代碼示例
- C++ Math isgreater()用法及代碼示例
- C++ Math fabs()用法及代碼示例
- C++ Math islessgreater()用法及代碼示例
- C++ Math log2()用法及代碼示例
- C++ Math nearbyint()用法及代碼示例
- C++ Math tan()用法及代碼示例
- C++ Math log()用法及代碼示例
- C++ Math nextafter()用法及代碼示例
- C++ Math fdim()用法及代碼示例
- C++ Math isfinite()用法及代碼示例
- C++ Math erfc()用法及代碼示例
- C++ Math sinh()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Math acos()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。