Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

cplxcartpol Cartesian/Polar functions

&pagelevel(3)&pagelevel


This section describes the Cartesian and Polar functions in the class complex.


#include <complex.h>

class complex

{

public:

friend double

abs(complex);

friend double

arg(complex);

friend complex

conj(complex);

friend double

imag(const complex&);

friend double

norm(complex);

friend complex

polar(double, double = 0.0);

friend double

real(const complex&);

/* 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:

7.64842 6.44218

%  CCM0998 CPU time used: 0.0006 seconds

SEE ALSO


cplxerr, cplxerr, cplxops, cplxtrig