Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!mouse From: mouse@thunder.mcrcim.mcgill.edu (der Mouse) Newsgroups: comp.lang.c Subject: Re: complex data manipulation Message-ID: <1991Jun1.213156.28507@thunder.mcrcim.mcgill.edu> Date: 1 Jun 91 21:31:56 GMT References: <1991May29.211117.29303@mailer.cc.fsu.edu> Organization: McGill Research Centre for Intelligent Machines Lines: 34 In article <1991May29.211117.29303@mailer.cc.fsu.edu>, wjbrown@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 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@larry.mcrcim.mcgill.edu