449,312 Members | 1,850 Online
Need help? Post your question and get tips & solutions from a community of 449,312 IT Pros & Developers. It's quick & easy.

# Built-in primitives for complex

 P: n/a Dear all, In C99, complex is now built in, and the C library contains functions for complex exp, etc. It is not so easy to find info about the syntax if one is not willing to buy the ISO/ANSI standard document, despite the fact that implementations are already available Also, because it is built in, one cannot figure out the syntax from the header files. I have a few questions a) How do I initialize a say double complex from a pair of doubles, or, more generally, how do I convert a pair of doubles to a double complex. Of course one could do z = x + I*y where hopefully the complex multiply and add can be optimized away, but there must be better ways. b) Primitives for say complex conjugates. If someone can point to open sources of information I would be grateful. Carl-Olof Almbladh Nov 14 '05 #1
4 Replies

 P: n/a In message co*@urd.teorfys.lu.se (Carl-Olof Almbladh) wrote: a) How do I initialize a say double complex from a pair of doubles, or, more generally, how do I convert a pair of doubles to a double complex. Of course one could do z = x + I*y where hopefully the complex multiply and add can be optimized away, but there must be better ways. Nope. That's it. How can that be bettered? It exactly reflects standard mathematical notation. A compiler must be capable of optimising away the apparent add and multiply, as such an expression is a valid initialiser for a static variable. There is a minor issue there to do with signalling NaNs, although I'm not sure any current implementations support signalling NaNs fully & the standard doesn't cover them anyway. So it's a moot point. Also note that a good implementation should implement imaginary types, in which case there's no actual complex arithmetic there anyway. I*y is imaginary * real -> imaginary, and the "add" just combines the two parts: real + imaginary -> complex. b) Primitives for say complex conjugates. These are in . conj() does a complex conjugate; in a typical good implementation this will be a macro invoking a built-in operator or function. -- Kevin Bracey, Principal Software Engineer Tematic Ltd Tel: +44 (0) 1223 503464 182-190 Newmarket Road Fax: +44 (0) 1728 727430 Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/ Nov 14 '05 #2

 P: n/a In co*@urd.teorfys.lu.se (Carl-Olof Almbladh) writes: In C99, complex is now built in, and the C librarycontains functions for complex exp, etc. It is notso easy to find info about the syntax if oneis not willing to buy the ISO/ANSI standard document, One can get N869 for free (use Google) which is practically as good as the standard itself for your purposes. One complex related example has a glitch, but the same glitch is present in the standard itself: [#24] EXAMPLE 1 Provided that has been #included, the declarations int i = 3.5; complex c = 5 + 3 * I; define and initialize i with the value 3 and c with the value 5.0+3.0i. The correct version is: double complex c = 5 + 3 * I; Dan -- Dan Pop DESY Zeuthen, RZ group Email: Da*****@ifh.de Currently looking for a job in the European Union Nov 14 '05 #3

 P: n/a Dan Pop wrote: In co*@urd.teorfys.lu.se (Carl-Olof Almbladh) writes:In C99, complex is now built in, and the C librarycontains functions for complex exp, etc. It is notso easy to find info about the syntax if oneis not willing to buy the ISO/ANSI standard document, One can get N869 for free (use Google) which is practically as good as the standard itself for your purposes. One complex related example has a glitch, but the same glitch is present in the standard itself: [#24] EXAMPLE 1 Provided that has been #included, the declarations int i = 3.5; complex c = 5 + 3 * I; define and initialize i with the value 3 and c with the value 5.0+3.0i. The correct version is: double complex c = 5 + 3 * I; Dan -- Dan Pop DESY Zeuthen, RZ group Email: Da*****@ifh.de Currently looking for a job in the European Union I note you write it 5 + 3*I whereas the OP said 5 + I*3 . Are they equivalent and/or equally acceptable? -- Julian V. Noble Professor Emeritus of Physics jv*@lessspamformother.virginia.edu ^^^^^^^^^^^^^^^^^^ http://galileo.phys.virginia.edu/~jvn/ "For there was never yet philosopher that could endure the toothache patiently." -- Wm. Shakespeare, Much Ado about Nothing. Act v. Sc. 1. Nov 14 '05 #4

 P: n/a On Thu, 14 Oct 2004 13:40:52 -0400, Julian V. Noble wrote: I note you write it 5 + 3*I whereas the OP said 5 + I*3 . Are they equivalent and/or equally acceptable? They must be. If I is defined as the complex unit, which it seems to be, and multiplication still has a higher precedence than addition, a fact only a fool would change, then 5 + 3*I must be equal to 5 + I*3. Nov 14 '05 #5

### This discussion thread is closed

Replies have been disabled for this discussion.