Question: Representing complex numbers in C
Kevin Grover
grover at dawkins.cs.unlv.edu
Sat Mar 2 07:24:37 AEST 1991
In article <12620.27cbe36f at ecs.umass.edu>, lim at ecs.umass.edu writes:
) I'd appreciated it if anyone out there can help me out with this problem. It
) concerns representation of complex numbers in C. I understand that Fortran has
) a data type COMPLEX that allows complex variables to be treated like any int,
) float, or double. I need to do the following in C:
)
) COMPLEX x, y, z;
) z = x + y;
) etc.
)
) The following won't work, obviously...
)
) struct
) {
) double real;
) double imaginary;
) }
) COMPLEX;
)
) Thanks in advance.
)
)
) Jonathan Lim
Well, as you've seen from the other messages, there is no easy way to do this
in C. However, I ran into this problem also while trying to do some Numerical
Analysis homework. Rather than using FORTrash, I wrote a complex number library
for C. Even though C++ makes this library obsolete, I still have it. If there
is some interest I could send it out. I am not very familar with the practices
of sending code out on the net. Where should I put the code? On NEWS or an
FTP site? It is many C files and some batch files to compile them into a
library (for the various memory models.)
It supports quite a few functions: log, sin, cos, tan, sinh, cosh, tanh
add, sub, mul, log, exp, (and more)
Some of the routines will also take multiple arguments.
I sort of assumed the someone else would have already written something like this
since it is not very difficult, but I didn'y have time to look and ask around.
Let me know if anyone would like this code, and tell me where and how to post it.
(it is written for Turbo C 2.0, but should work on any compiler.)
--
+-------------------------------------------------+----------------------+
| Kevin Grover UNLV Computer Science | Home of the |
| grover at cs.unlv.edu Las Vegas, Nevada | Running REBELS |
+-------------------------------------------------+----------------------+
More information about the Comp.lang.c
mailing list