1<html lang="en"> 2<head> 3<title>Complex - Using the GNU Compiler Collection (GCC)</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Using the GNU Compiler Collection (GCC)"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="C-Extensions.html#C-Extensions" title="C Extensions"> 9<link rel="prev" href="_005f_005fint128.html#g_t_005f_005fint128" title="__int128"> 10<link rel="next" href="Floating-Types.html#Floating-Types" title="Floating Types"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 141998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 152010 Free Software Foundation, Inc. 16 17Permission is granted to copy, distribute and/or modify this document 18under the terms of the GNU Free Documentation License, Version 1.3 or 19any later version published by the Free Software Foundation; with the 20Invariant Sections being ``Funding Free Software'', the Front-Cover 21Texts being (a) (see below), and with the Back-Cover Texts being (b) 22(see below). A copy of the license is included in the section entitled 23``GNU Free Documentation License''. 24 25(a) The FSF's Front-Cover Text is: 26 27 A GNU Manual 28 29(b) The FSF's Back-Cover Text is: 30 31 You have freedom to copy and modify this GNU Manual, like GNU 32 software. Copies published by the Free Software Foundation raise 33 funds for GNU development.--> 34<meta http-equiv="Content-Style-Type" content="text/css"> 35<style type="text/css"><!-- 36 pre.display { font-family:inherit } 37 pre.format { font-family:inherit } 38 pre.smalldisplay { font-family:inherit; font-size:smaller } 39 pre.smallformat { font-family:inherit; font-size:smaller } 40 pre.smallexample { font-size:smaller } 41 pre.smalllisp { font-size:smaller } 42 span.sc { font-variant:small-caps } 43 span.roman { font-family:serif; font-weight:normal; } 44 span.sansserif { font-family:sans-serif; font-weight:normal; } 45--></style> 46<link rel="stylesheet" type="text/css" href="../cs.css"> 47</head> 48<body> 49<div class="node"> 50<a name="Complex"></a> 51<p> 52Next: <a rel="next" accesskey="n" href="Floating-Types.html#Floating-Types">Floating Types</a>, 53Previous: <a rel="previous" accesskey="p" href="_005f_005fint128.html#g_t_005f_005fint128">__int128</a>, 54Up: <a rel="up" accesskey="u" href="C-Extensions.html#C-Extensions">C Extensions</a> 55<hr> 56</div> 57 58<h3 class="section">6.10 Complex Numbers</h3> 59 60<p><a name="index-complex-numbers-2281"></a><a name="index-g_t_0040code_007b_005fComplex_007d-keyword-2282"></a><a name="index-g_t_0040code_007b_005f_005fcomplex_005f_005f_007d-keyword-2283"></a> 61ISO C99 supports complex floating data types, and as an extension GCC 62supports them in C90 mode and in C++, and supports complex integer data 63types which are not part of ISO C99. You can declare complex types 64using the keyword <code>_Complex</code>. As an extension, the older GNU 65keyword <code>__complex__</code> is also supported. 66 67 <p>For example, ‘<samp><span class="samp">_Complex double x;</span></samp>’ declares <code>x</code> as a 68variable whose real part and imaginary part are both of type 69<code>double</code>. ‘<samp><span class="samp">_Complex short int y;</span></samp>’ declares <code>y</code> to 70have real and imaginary parts of type <code>short int</code>; this is not 71likely to be useful, but it shows that the set of complex types is 72complete. 73 74 <p>To write a constant with a complex data type, use the suffix ‘<samp><span class="samp">i</span></samp>’ or 75‘<samp><span class="samp">j</span></samp>’ (either one; they are equivalent). For example, <code>2.5fi</code> 76has type <code>_Complex float</code> and <code>3i</code> has type 77<code>_Complex int</code>. Such a constant always has a pure imaginary 78value, but you can form any complex value you like by adding one to a 79real constant. This is a GNU extension; if you have an ISO C99 80conforming C library (such as GNU libc), and want to construct complex 81constants of floating type, you should include <code><complex.h></code> and 82use the macros <code>I</code> or <code>_Complex_I</code> instead. 83 84 <p><a name="index-g_t_0040code_007b_005f_005freal_005f_005f_007d-keyword-2284"></a><a name="index-g_t_0040code_007b_005f_005fimag_005f_005f_007d-keyword-2285"></a>To extract the real part of a complex-valued expression <var>exp</var>, write 85<code>__real__ </code><var>exp</var>. Likewise, use <code>__imag__</code> to 86extract the imaginary part. This is a GNU extension; for values of 87floating type, you should use the ISO C99 functions <code>crealf</code>, 88<code>creal</code>, <code>creall</code>, <code>cimagf</code>, <code>cimag</code> and 89<code>cimagl</code>, declared in <code><complex.h></code> and also provided as 90built-in functions by GCC. 91 92 <p><a name="index-complex-conjugation-2286"></a>The operator ‘<samp><span class="samp">~</span></samp>’ performs complex conjugation when used on a value 93with a complex type. This is a GNU extension; for values of 94floating type, you should use the ISO C99 functions <code>conjf</code>, 95<code>conj</code> and <code>conjl</code>, declared in <code><complex.h></code> and also 96provided as built-in functions by GCC. 97 98 <p>GCC can allocate complex automatic variables in a noncontiguous 99fashion; it's even possible for the real part to be in a register while 100the imaginary part is on the stack (or vice-versa). Only the DWARF2 101debug info format can represent this, so use of DWARF2 is recommended. 102If you are using the stabs debug info format, GCC describes a noncontiguous 103complex variable as if it were two separate variables of noncomplex type. 104If the variable's actual name is <code>foo</code>, the two fictitious 105variables are named <code>foo$real</code> and <code>foo$imag</code>. You can 106examine and set these two fictitious variables with your debugger. 107 108 </body></html> 109 110