Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

20.9 Complex Numbers

ISO C99 introduces support for complex numbers in C. This is done with a new type qualifier, complex. It is a keyword if and only if complex.h has been included. There are three complex types, corresponding to the three real types: float complex, double complex, and long double complex.

To construct complex numbers you need a way to indicate the imaginary part of a number. There is no standard notation for an imaginary floating point constant. Instead, complex.h defines two macros that can be used to create complex numbers.

— Macro: const float complex _Complex_I

This macro is a representation of the complex number “0+1i”. Multiplying a real floating-point value by _Complex_I gives a complex number whose value is purely imaginary. You can use this to construct complex constants:

          3.0 + 4.0i = 3.0 + 4.0 * _Complex_I
     

Note that _Complex_I * _Complex_I has the value -1, but the type of that value is complex.

_Complex_I is a bit of a mouthful. complex.h also defines a shorter name for the same constant.

— Macro: const float complex I

This macro has exactly the same value as _Complex_I. Most of the time it is preferable. However, it causes problems if you want to use the identifier I for something else. You can safely write

          #include <complex.h>
          #undef I
     

if you need I for your own purposes. (In that case we recommend you also define some other short name for _Complex_I, such as J.)


 
 
  Published under the terms of the GNU General Public License Design by Interspire