Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Complex Numbers in C

1 view
Skip to first unread message

Y H Ng

unread,
Oct 18, 1996, 3:00:00 AM10/18/96
to

I'm new to C. Can anyone tell me if there are any complex number handling
facilities available in C? I usually program in Fortran but I'd like to
learn C as well, except someone told me that using complex numbers could
be quite tricky in C...

--
Alex

--"Night has fallen and the Foul
are abroad! Two days have passed
since the War of the Solstice
began."


Brahim Djoudi

unread,
Oct 19, 1996, 3:00:00 AM10/19/96
to

Hi Alex !

I recommend you to use the C++ library complex.h which handles complex
numbers. If you are new in C, you should learn and use C before migrating
to C++. So, you can use C code with a C/C++ compiler (then you need not
learn any C++ feature). Advantage : you will get more error messages and
warnings.
In conclusion, the problem becomes : getting a C/C++ compiler ?

Cordially.

Brahim Djoudi
GIAT Industries
155, av. de Grande-Bretagne
31000 Toulouse

Stephen Baynes

unread,
Oct 21, 1996, 3:00:00 AM10/21/96
to

Brahim Djoudi (bd...@club-internet.fr) wrote:
: I recommend you to use the C++ library complex.h which handles complex

Please note that C++ libraries do not work with ISO standard C compilers.

--
Stephen Baynes Stephen...@soton.sc.philips.com
Philips Semiconductors Ltd [SERI baynes@ukpsshp1]
Southampton +44 (01703) 316431
United Kingdom My views are my own.
Are you using ISO8859-1? Do you see © as copyright, ÷ as division and ½ as 1/2?

Ronald Fischer

unread,
Oct 21, 1996, 3:00:00 AM10/21/96
to Y H Ng

Y H Ng wrote:
>
> I'm new to C. Can anyone tell me if there are any complex number handling
> facilities available in C? I usually program in Fortran but I'd like to
> learn C as well, except someone told me that using complex numbers could
> be quite tricky in C...

You don't have a builtin COMPLEX as in FORTRAN, but it is not tricky to
provide your own (well, except probably for some math functions....),
using a struct with two doubles.

--

Ronald Otto Valentin Fischer
business: ronald....@uebemc.siemens.de
private: ronald....@acm.org
http://ourworld.compuserve.com/homepages/ronald_fischer

Martin Vicente

unread,
Oct 23, 1996, 3:00:00 AM10/23/96
to

Avec GNU CC, il existe un type complexe en utilisant le qualifieur
`__complex__'. Extrait de la doc info de gcc :

Complex Numbers
===============

GNU C supports complex data types. You can declare both complex
integer types and complex floating types, using the keyword
`__complex__'.

For example, `__complex__ double x;' declares `x' as a variable
whose real part and imaginary part are both of type `double'.
`__complex__ short int y;' declares `y' to have real and imaginary
parts of type `short int'; this is not likely to be useful, but it
shows that the set of complex types is complete.

To write a constant with a complex data type, use the suffix `i' or
`j' (either one; they are equivalent). For example, `2.5fi' has type
`__complex__ float' and `3i' has type `__complex__ int'. Such a
constant always has a pure imaginary value, but you can form any
complex value you like by adding one to a real constant.

To extract the real part of a complex-valued expression EXP, write
`__real__ EXP'. Likewise, use `__imag__' to extract the imaginary part.

The operator `~' performs complex conjugation when used on a value
with a complex type.
--
Martin e-mail: vic...@cena.dgac.fr - Web: http://www.cena.dgac.fr/~vicente/

~~~~~~~ "Science sans conscience n'est que ruine de l'āme" (Rabelais) ~~~~~~~

Norman Diamond

unread,
Oct 24, 1996, 3:00:00 AM10/24/96
to

In article <lnu3rl2...@cena.dgac.fr>, Martin Vicente <vic...@cena.dgac.fr> writes:
>Avec GNU CC, il existe un type complexe en utilisant le qualifieur
>`__complex__'. Extrait de la doc info de gcc :

そうですね。しかし、それは gcc の implementation extension です。
ニューズグループ comp.std.c の中で、gcc より ISO/IEC 9899:1990 の
ほうが大切でしょう。

--
<< If this were the company's opinion, I would not be allowed to post it. >>
"I paid money for this car, I pay taxes for vehicle registration and a driver's
license, so I can drive in any lane I want, and no innocent victim gets to call
the cops just 'cause the lane's not goin' the same direction as me" - J Spammer

Peter Seebach

unread,
Oct 27, 1996, 2:00:00 AM10/27/96
to

In article <54mjou$l...@usenet.pa.dec.com>,
Norman Diamond <dia...@tbj.dec.com> wrote:
[griping about discussing gcc's __complex__ here...]

Real Soon Now I'll be posting some info on what happened at the Toronto
meeting, but part of it is... we expect to have complexes as a built-in-type
in C9X, but (for historical reasons) only if you #include <complex.h>.

(And BTW, these meetings are *fun*. Anyone looking for a good way to help
make the next version of C better, and/or spend an enjoyable week, should
consider joining. :) )

-s
--
Peter Seebach - se...@solon.com - Copyright 1996 - http://www.solon.com/~seebs
Unix/C Wizard - send mail for help, or send money for consulting!
The *other* C FAQ, the hacker FAQ, et al. See web page above.
Unsolicited email (junk mail and ads) is unwelcome, and will be billed for.

0 new messages