Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!tahoe!jimi!dawkins.cs.unlv.edu!grover From: grover@dawkins.cs.unlv.edu (Kevin Grover) Newsgroups: comp.lang.c Subject: Re: Question: Representing complex numbers in C Message-ID: <1991Mar1.202437.4400@unlv.edu> Date: 1 Mar 91 20:24:37 GMT References: <12620.27cbe36f@ecs.umass.edu> Sender: news@unlv.edu (News User) Reply-To: grover@dawkins.cs.unlv.edu (Kevin Grover) Organization: UNLV Computer Science and Electrical Engineering Lines: 49 In article <12620.27cbe36f@ecs.umass.edu>, lim@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@cs.unlv.edu Las Vegas, Nevada | Running REBELS | +-------------------------------------------------+----------------------+