This section describes the Cartesian and Polar functions in the class complex. #include <complex.h> class complex { public:
/* other declarations */ }; | |||||||||||||||
double d = abs(complex x) Returns the absolute value or magnitude of x. double d = norm(complex x) Returns the square of the magnitude of x, and is intended for comparison of magnitudes. The norm() function is faster than abs(). With norm(), however, an overflow error is more likely since the square of the magnitude is returned. double d = arg(complex x) Returns the angle of x, measured in radians in the range -pi to pi. complex y = conj(complex x) Returns the complex conjugate of x. If x is specified in the form (real, imag), then conj(x) is identical to (real, -imag). complex y = polar(double m, double a=0.0); Returns a value of type complex, given a pair of polar coordinates: magnitude m, and angle a, measured in radians. double d = real(complex &x) Returns the real part of x. double d = imag(complex &x) Returns the imaginary part of x. | |||||||||||||||
EXAMPLE | |||||||||||||||
The following program converts a complex number to the Polar coordinate system and then prints it: #include <iostream.h> #include <complex.h> main () { complex d; d = polar (10.0, 0.7); cout <<real(d)<<" "<<imag(d); cout <<"\n"; return 0; } The result of executing the program is:
| |||||||||||||||
SEE ALSO | |||||||||||||||