在C++中,asin()和atan()是用於數學計算的預定義函數。 math.h是各種數學函數所需的頭文件。該庫中所有可用的函數都將double作為參數,並返回double作為結果。
asin()
asin()函數用於查找數字的反正弦值,表示對該函數賦予正弦值,它將以弧度返回對應於該值的角度。在三角學中,反正弦是正弦的逆運算。
注意:傳遞給此函數的參數必須在[-1,1]之間。
用法:
double asin(double k) 參數: k is the value whose corresponding angle we have to find.
// CPP code to illustrate
// the use of asin function
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
int main()
{
double k, ret, val;
// Take any value between [-1, 1]
k = 0.5;
ret = asin(k);
val = (ret * 180) / PI;
cout << "The arcsine of " << k
<< " is " << ret << " radians and "
<< val << " degrees";
return 0;
}
輸出:
The arcsine of 0.5 is 0.523599 radians and 30 degrees
atan()
atan()函數用於查找數字的反正切,表示對該函數給出正切值,它將以弧度返回對應於該值的角度。反正切是切線的逆運算。此函數接受所有實數。
用法:
double atan(double k) 參數: k is the value whose corresponding angle we have to find.
// CPP code to illustrate
// the use of atan function
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
int main()
{
double k, ret, val;
// Take any value
k = 1.0;
ret = atan(k);
val = (ret * 180) / PI;
cout << "The arctangent of " << k
<< " is " << ret << " radians and "
<< val << " degrees";
return 0;
}
輸出:
The arctangent of 1 is 0.785398 radians and 45 degrees
相關用法
- C++ valarray asin()用法及代碼示例
- C++ valarray atan()用法及代碼示例
- C++ complex asin()用法及代碼示例
- C++ complex atan()用法及代碼示例
- C++內聯函數用法及代碼示例
- C/C++ fill()、fill_n()用法及代碼示例
- C/C++ abs(), labs(), llabs()用法及代碼示例
注:本文由純淨天空篩選整理自AKASH GUPTA 6大神的英文原創作品 asin() and atan() functions in C/C++ with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。