Go to the previous, next section.
Class Complex
is implemented in a way similar to that
described by Stroustrup. In keeping with libg++ conventions,
the class is named Complex
, not complex
.
Complex arithmetic and relational operators are provided
(+, -, *, /, +=, -=, *=, /=, ==, !=
).
Attempted division by (0, 0) triggers an exception.
Complex numbers may be constructed and used in the following ways:
Complex x;
Complex x = 2; Complex y(2.0);
Complex x(2, 3);
Complex u(x); Complex v = x;
double real(Complex& x);
double imag(Complex& x);
double abs(Complex& x);
double norm(Complex& x);
double arg(Complex& x);
Complex polar(double r, double t = 0.0);
Complex conj(Complex& x);
Complex cos(Complex& x);
Complex sin(Complex& x);
Complex cosh(Complex& x);
Complex sinh(Complex& x);
Complex exp(Complex& x);
Complex log(Complex& x);
Complex pow(Complex& x, long p);
Complex pow(Complex& x, Complex& p);
Complex sqrt(Complex& x);
ostream << x;
istream >> x;
Go to the previous, next section.