Simple Complex

A complex structure is defined in math.h.  I chose in interpolation\findfun\Findfun.htm do define a similar

struct bcmpl {double real;double aimag;};

I also used this in Fourier\Violin.htm. 

With both my definition and the one in math.h, the local code needs to do all of the complex arithmetic in its own routines.  These usually amount to exponentials, conjugates and norms.

Cpp Complex

            To use complex numbers with all functions logically defined in Borland Cpp, all you have to do is to include complex.h. – well maybe a bit more.  Most of the examples and simple codes for Borland do not compile in Watcom and v.v.

            I put together a short code using complex numbers that works both in Watcom Cpp and in Borland Cpp

cpp\complex.wpj cpp\COMPLEX1.CPP

#include <complex.h>  /* includes reasonable definitions for all functions – see cbooks.hlp */

#include <stdio.h>  /* needed for the printf function */

 

 int main()

 { complex a(1.2,3.4);

   complex b(17.3,18.9);

   double c;

   printf(" a = %lf %lf \n",real(a),imag(a));

   printf(" b = %lf %lf \n",real(b),imag(b));

 /* norm is real*real + imag*imag */

   c=norm(a);

   printf("c = %lf \n",c);

   cout << "a = " << a << ", b = " << b << endl;  /* usual Cpp output method */

   a += b;

   printf(" a+b = %lf %lf \n",real(a),imag(a));

   cout << "a = " << a << ", b = " << b << endl;

   return 0; }