C++ 中複數的 proj() 函式


本文演示了使用 proj() 函式對複數執行投影。C++ 程式設計中的 proj() 方法語法如下;

template <class T> complex<T>
proj (const complex<T>& z);

示例

proj() 方法接受一個引數作為自變數,它表示複數,並返回複數的投影,如下示例中所示;

 實戰演示

#include <iostream>
#include <complex>
using namespace std;
int main(){
   std::complex<double> c1(3, 5);
   cout << "Proj" << c1 << " = " << proj(c1) << endl;
   std::complex<double> c2(0, -INFINITY);
   cout << "Proj" << c2 << " = " << proj(c2) << endl;
   std::complex<double> c3(INFINITY, -1);
   cout << "Proj" << c3 << " = " << proj(c3) << endl;
}

必須在原始碼中匯入庫 complex.h 以獲取投影方法實現的定義。在上例成功編譯後,將對傳出的複數產生以下結果;

輸出

Proj(3,5) = (3,5)
Proj(0,-inf) = (inf,-0)
Proj(inf,1) = (inf,-0)

更新於:16-Jan-2020

113 次瀏覽

開啟你的 職業生涯

完成課程,獲得認證

開始入門
廣告