This class implements complex numbers. Using overloaded functions and operators, you can treat complex numbers like you treat reals or integers. You can use the following:
#include <oldcomplex.h>
complex z1; // Uninitialized complex z2(1.0,2.0); // Initialized with two numbers complex z3 = z2; // Initialized with a complex number
complex z1, z2(5.0,6.0); z1.real() = z2.imag(); z1.imag() = z2.real();
#include <complex.h> #include <iostream.h> int main() { complex z1(1.1, 2.0), z2; cout << "Enter z2: "; cin >> z2; cout << "z1 = " << z1 << '\n'; cout << "z2 = " << z2 << '\n'; return 0; }
Enter z2: 10 9.8 z1 = (1.1, 2) z2 = (10,9.8)
cout << sin(complex(1,1));
complex z;
complex z1(1.2,3.0), z2(3,4);
#include <oldcomplex.h> complex complexFunc() { // Invokes complex(double, double) complex z1(2.0,4.0); // Invokes complex(const complex&) complex z2 = z1; // Invokes complex(const complex&) to // create a temporary variable and adds // it to z1. return complex(1.1, 2.2) + z1; }
The arg function is equivalent to:
atan2(imag(x), real(x))
For complex::imag For complex::real #include <oldcomplex.h> #include <oldcomplex.h> complex z1(1.0,2.0), z2; complex z1(1.0,2.0), z2; z1.imag() = z2.imag(); z1.real() = z2.real();
complex(range * cos(theta), range * sin(theta));
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル