complex data manipulation
der Mouse
mouse at thunder.mcrcim.mcgill.edu
Sun Jun 2 07:31:56 AEST 1991
In article <1991May29.211117.29303 at mailer.cc.fsu.edu>, wjbrown at evax0.eng.fsu.edu (WILLIAM J. BROWN) writes:
> I'm writing a program in C (of course) which requires the inversion
> of a rather large matrix. This by itself is no problem except that
> some of the elements in the array are complex. Is there an easy way
> to handle complex data in C?
Not especially. You can define a small struct and then have functions
that operate on these things, but C provides no way to make the
"natural" way of writing things with the usual arithmetic operators
work. For that you need a language that allows the programmer to
extend operator polymorphism, like C++.
> I have a book titled *C TOOLS for Scientists and Engineers* where the
> author uses the header file #include <complex.h> and uses functions
> such as CADD(),CSUB(),CMULT() etc. for complex arithmetic.
Not hard to do. Something like
complex.h:
typedef struct { double r; double i; } complex;
complex CADD(complex,complex);
[prototypes for other functions omitted]
complex.c:
complex CADD(complex a, complex b)
{ complex sum; sum.r = a.r + b.r; sum.i = a.i + b.i; return(sum); }
[code for other functions omitted]
der Mouse
old: mcgill-vision!mouse
new: mouse at larry.mcrcim.mcgill.edu
More information about the Comp.lang.c
mailing list