C++ 中複數的 tan() 函式
在本文中,我們將討論 C++ STL 中複數 tan() 函式的工作原理、語法和示例。
複數的 tan() 函式是 <complex> 標頭檔案中的函式。此函式用於求與之關聯的複數的正切值。此函式是 <cmath> 標頭檔案中的簡單 tan() 函式的複數版本。
什麼是複數?
複數是實數和虛數的組合。
它們表示為:a+bi
其中 a 和 b 是實數,i 是虛數。
語法
template<class T> complex<T> tan (const complex<T>& num);
引數
此函式僅接受一個引數,即 num,它是一個複數值。
返回值
它返回 num 的正切值。
示例
Input: complex <double> num(0.0, 1.0); tan(num); Output: (0, 1.55741)
示例
#include <iostream> #include <complex> using namespace std; int main () { complex<double> tan_num(9.1, 2.6); cout<<"tan of "<<tan_num<<" is "<<tan(tan_num); return 0; }
輸出
如果我們執行上述程式碼,它將生成以下輸出:
tan of (9.1, 2.6) is (-0.00661488, 0.99123)
示例
#include <iostream> #include <complex> using namespace std; int main () { complex<double> tan_num(1.0, 0.0); cout<<"tan of "<<tan_num<<" is "<<tan(tan_num); return 0; }
輸出
如果我們執行上述程式碼,它將生成以下輸出:
tan of (1, 0) is (1.55741, 0)
廣告宣傳