Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

cplxexp Transcendental functions

This section describes the transcendental functions in the class complex.


#include <complex.h>

class complex
{

public:

friend complex exp(complex);
friend complex log(complex);
friend complex pow(double, complex);
friend complex pow(complex, int);
friend complex pow(complex, double);
friend complex pow(complex, complex);
friend complex sqrt(complex);
};


complex z = exp(complex x)

Returns ex.

complex z = log(complex x)

Returns the natural logarithm of x.

complex z = pow(complex x, complex y)

Returns xy.

complex z = sqrt(complex x)

Returns the square root of x, contained in the first or fourth quadrants of the
complex plane.

RETURN VALUES

exp returns (0.0, 0.0) when the real part of x is so small, or the imaginary part is so
large, as to cause overflow. When the real part is large enough to cause overflow, expreturns:

(HUGE, HUGE) if the cosine and sine of the imaginary part of x is > 0;


(HUGE, -HUGE) if the cosine is > 0 and the sine is
(-HUGE, HUGE) if the sine is > 0 and the cosine is
(-HUGE, -HUGE) if the sine and cosine are     0.

0;
0;


This section describes the transcendental functions in the class complex.


#include <complex.h>

class complex
{

public:

friend complex exp(complex);
friend complex log(complex);
friend complex pow(double, complex);
friend complex pow(complex, int);
friend complex pow(complex, double);
friend complex pow(complex, complex);
friend complex sqrt(complex);

};


complex z = exp(complex x)

Returns ex.

complex z = log(complex x)

Returns the natural logarithm of x.

complex z = pow(complex x, complex y)

Returns xy.

complex z = sqrt(complex x)

Returns the square root of x, contained in the first or fourth quadrants of the
complex plane.

RETURN VALUES


exp returns (0.0, 0.0) when the real part of x is so small, or the imaginary part is so large, as to cause overflow. When the real part is large enough to cause overflow, exp returns:

  • (HUGE, HUGE), if the cosine and sine of the imaginary part of x is > 0;
  • (HUGE, -HUGE), if the cosine is > 0 and the sine is <= 0
  • (-HUGE, HUGE), if the sine is > 0 and the cosine is <= 0
  • (-HUGE, -HUGE), if the sine and cosine are <= 0 sind.

In all these cases, errno is set to ERANGE.

log returns (-HUGE, 0.0) and sets errno to EDOM when x is (0.0, 0.0). A message indicating SING error is printed on the standard error output.

These error handling routines can be changed with the complex_error() function (see section "cplxerr Error handling functions").

EXAMPLE

The following program prints a set of complex numbers and their exponential powers.

#include <iostream.h>
#include <complex.h>
main()
{
  complex c;
  for (c = complex(1.0,1.0); real(c) < 4.0; c += complex(1.0,1.0))
  {
    cout <<c<<" "<<exp(c)<<"\n";
  }
  return 0;
}

The result of executing the program is:

( 1, 1) ( 1.46869, 2.28736)
( 2, 2) ( -3.07493, 6.71885)
( 3, 3) ( -19.8845, 2.83447)
%  CCM0998 CPU time used: 0.0012 seconds

Note that complex numbers can be printed by using the << operator and can be processed as easily as numbers of type float or double.

SEE ALSO


cplxcartpolcplxerrcplxops, cplxtrig