Output of file : COMPLEX.DOC contained in archive : ZPP10.ZIP

Z++ Version 1.0

04/03/92

Z++ is a public domain complex number class written in C++. The distri-
buted files are:

complex.cpp source code for Z++
complex.doc this file
z_test.cpp demonstration of complex numbers
fft.cpp fft using Z++
signal.dat data file for testing the fft

To use the complex number class, simply #include "complex.h" in your source
and add complex.cpp to the project or make file. You may use and distribute
this code freely, but all distributed copies must be unmodified, and there
may be no distribution charges. Comments, suggestions for improvement, and
bug reports may be sent to me via CompuServe (72137,2657), or mail them to:

Carl Moreland
4314 Filmore Rd
Greensboro, NC 27409

---------------------------------------------------------------------------
---------------------------------------------------------------------------

Introduction:

---------------------------------------------------------------------------
Complex numbers may be declared or initialized in the following ways:

complex z; // z is initialized to (0,0)
complex z(3); // z = (3,0)
complex z = 3; // z = (3,0)
complex z(3,4); // z = (3,4)
complex z = complex(3,4) // z = (3,4)
complex z = x; // set equal to a double/float/int
complex z1 = z2; // set equal to another complex

Uninitialized complex variables are set to (0,0) by the default construc-
tor, and variables that are set equal to a single number have their imagi-
nary part set to zero.

The following operators are available:

= see above
- -= subtraction
* *= multiplication
/ /= division
^ power (z1^z2)
== != comparison

The following functions are available:

re real part
im imaginary part
real real part
imag imaginary part
mag magnitude (sqrt(x**2 + y**2))
arg argument (atan(y/x))
ang angle (same as argument)
ph phase (same as argument)
conj complex conjugate (x, -y)
norm norm (x**2 + y**2)
abs absolute value (same as magnitude)
sqrt square root
pow power
exp exponential
log natural log
ln natural log
log10 log (base 10)
cos cosine
sin sine
tan tangent
acos arccosine
asin arcsine
atan arctangent
cosh hyperbolic cosine
sinh hyperbolic sine
tanh hyperbolic tangent
rtop rectangular-to-polar conversion
ptor polar-to-rectangular conversion
topolar converts z to polar form
torect converts z to rectangular form

SetArgMode ¿
SetPrintMode Ã See text below
SetLetter Ù

---------------------------------------------------------------------------

Most features of Z++ are standard. However, there are a few things that
are unique and should be explained.

The conversion functions rtop() and ptor() accept a complex number as
the argument and return a new complex number as the converted result. The
member methods topolar() and torect() will convert the instance internally
and return a reference to it. Remember though that all math functions ex-
pect arguments in rectangular notation, not polar. If you convert a number
to polar and try to take the cosine, for instance, you will not get the
correct results.

There are two modes that can be set in Z++. The argument mode deter-
mines whether complex arguments (from the functions arg(), ang(), & ph())
are returned in radians (the default) or degrees. This mode can be set by
calling the function SetArgMode() with either Z_RADIANS or Z_DEGREES as
the mode parameter:

z1.SetArgMode(Z_DEGREES);

Because this mode is represented as a static class variable, setting it
will affect all complex numbers. The command above appears to set this mode
only for instance z1, which is not true. To eliminate this confusion, there
is a static instance named Complex declared in complex.h which should be
used to set this mode:

Complex.SetArgMode(Z_DEGREES);

Either way will work, but the second has the appearance of being global.

The other mode is the print mode which affects the format of cout. This
mode can be set by calling the function SetPrintMode() with either Z_COMMA
or Z_LETTER as the mode parameter:

Complex.SetPrintMode(Z_COMMA)
Complex.SetPrintMode(Z_LETTER)

The first mode causes complex numbers to printed with the format (x, y) by
cout. The second mode causes them to be formatted as x ñ iy. Like the argu-
ment mode, this mode is global for all complex numbers and therefore should
be set using the Complex instance.

Electrical engineers prefer to use the letter j as the complex operator
(the letter i denotes AC current). There is a function called SetLetter()
which accepts a character argument:

Complex.SetLetter('j');

If the print mode is set to Z_LETTER then cout will print a complex number
with the format x ñ jy.

Finally, besides the instance Complex used above there are four other
static instances declared:

Z0 = complex(0,0)
Z1 = complex(1,0)
Zi = complex(0,1)
Zinf = complex(HUGE_VAL, HUGE_VAL)

These are common useful numbers that can be used for assignments, compari-
sons, and equations.

---------------------------------------------------------------------------

FFT note:

The FFT program that is included was originally written in C and ran on
DOS, VMS, and Unix. It's purpose was to transform sinusoidal data from an
analog-to-digital converter and display the harmonics and relative bits of
accuracy. I have only converted the fft() routine to use the Z++ complex
numbers; the rest of the program remains pure C. The data file included for
testing the FFT is the actual results from a 12-bit ADC.

### 3 Responses to “Category : C++ Source CodeArchive   : ZPP10.ZIPFilename : COMPLEX.DOC”

1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/