C++ 中的acos() 函數以弧度返回數字(參數)的反餘弦值。
該函數在<cmath> 頭文件中定義。
[Mathematics] cos-1x = acos(x) [In C++ Programming];
acos() 原型 [從 C++ 11 標準開始]
double acos(double x); float acos(float x); long double acos(long double x); double acos (T x); // For integral type
參數:
acos() 函數采用 [-1, 1] 範圍內的單個強製參數。這是因為餘弦的值在 1 和 -1 的範圍內。
返回:
假設參數在 [-1, 1] 範圍內,acos() 函數返回 [0, π] 範圍內的值。
如果參數大於 1 或小於 -1,acos() 返回 NaN
,即不是數字。
參數 (x) | 返回值 |
---|---|
x = [-1, 1] | [0, π] 以弧度為單位 |
-1 > x 或 x > 1 | NaN(不是數字) |
示例 1:acos() 如何工作?
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = 0.0, result;
result = acos(x);
cout << "acos(x) = " << result << " radians" << endl;
// result in degrees
cout << "acos(x) = " << result*180/3.1415 << " degrees" << endl;
return 0;
}
運行程序時,輸出將是:
acos(x) = 1.5708 radians acos(x) = 90.0027 degrees
示例 2:acos() 具有整數類型的函數
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x = -1;
double result;
result = acos(x);
cout << "acos(x) = " << result << " radians" << endl;
// Converting result to degrees
cout << "acos(x) = " << result*180/3.1415 << " degrees";
return 0;
}
運行程序時,輸出將是:
acos(x) = 3.14159 radians acos(x) = 180.005 degrees
相關用法
- C++ acos()用法及代碼示例
- C++ complex acos()用法及代碼示例
- C++ complex acosh()用法及代碼示例
- C++ acosh()用法及代碼示例
- C++ atexit()用法及代碼示例
- C++ any_of()用法及代碼示例
- C++ atof()用法及代碼示例
- C++ abort()用法及代碼示例
- C++ atol()用法及代碼示例
- C++ array at()用法及代碼示例
- C++ array::fill()、array::swap()用法及代碼示例
- C++ atoll()用法及代碼示例
- C++ array::size()用法及代碼示例
- C++ array::rbegin()、array::rend()用法及代碼示例
- C++ atan()用法及代碼示例
- C++ complex abs()用法及代碼示例
- C++ array::front()、array::back()用法及代碼示例
- C++ array::front()用法及代碼示例
- C++ array get()用法及代碼示例
- C++ complex atanh()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ acos()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。