Complex.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>Using the GNU Compiler Collection (GCC): Complex</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Complex">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Complex">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="C-Extensions.html#C-Extensions" rel="up" title="C Extensions">
  30. <link href="Floating-Types.html#Floating-Types" rel="next" title="Floating Types">
  31. <link href="Long-Long.html#Long-Long" rel="prev" title="Long Long">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Complex"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Floating-Types.html#Floating-Types" accesskey="n" rel="next">Floating Types</a>, Previous: <a href="Long-Long.html#Long-Long" accesskey="p" rel="prev">Long Long</a>, Up: <a href="C-Extensions.html#C-Extensions" accesskey="u" rel="up">C Extensions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Complex-Numbers"></a>
  69. <h3 class="section">6.10 Complex Numbers</h3>
  70. <a name="index-complex-numbers"></a>
  71. <a name="index-_005fComplex-keyword"></a>
  72. <a name="index-_005f_005fcomplex_005f_005f-keyword"></a>
  73. <p>ISO C99 supports complex floating data types, and as an extension GCC
  74. supports them in C90 mode and in C++. GCC also supports complex integer data
  75. types which are not part of ISO C99. You can declare complex types
  76. using the keyword <code>_Complex</code>. As an extension, the older GNU
  77. keyword <code>__complex__</code> is also supported.
  78. </p>
  79. <p>For example, &lsquo;<samp>_Complex double x;</samp>&rsquo; declares <code>x</code> as a
  80. variable whose real part and imaginary part are both of type
  81. <code>double</code>. &lsquo;<samp>_Complex short int y;</samp>&rsquo; declares <code>y</code> to
  82. have real and imaginary parts of type <code>short int</code>; this is not
  83. likely to be useful, but it shows that the set of complex types is
  84. complete.
  85. </p>
  86. <p>To write a constant with a complex data type, use the suffix &lsquo;<samp>i</samp>&rsquo; or
  87. &lsquo;<samp>j</samp>&rsquo; (either one; they are equivalent). For example, <code>2.5fi</code>
  88. has type <code>_Complex float</code> and <code>3i</code> has type
  89. <code>_Complex int</code>. Such a constant always has a pure imaginary
  90. value, but you can form any complex value you like by adding one to a
  91. real constant. This is a GNU extension; if you have an ISO C99
  92. conforming C library (such as the GNU C Library), and want to construct complex
  93. constants of floating type, you should include <code>&lt;complex.h&gt;</code> and
  94. use the macros <code>I</code> or <code>_Complex_I</code> instead.
  95. </p>
  96. <a name="index-_005f_005freal_005f_005f-keyword"></a>
  97. <a name="index-_005f_005fimag_005f_005f-keyword"></a>
  98. <p>To extract the real part of a complex-valued expression <var>exp</var>, write
  99. <code>__real__ <var>exp</var></code>. Likewise, use <code>__imag__</code> to
  100. extract the imaginary part. This is a GNU extension; for values of
  101. floating type, you should use the ISO C99 functions <code>crealf</code>,
  102. <code>creal</code>, <code>creall</code>, <code>cimagf</code>, <code>cimag</code> and
  103. <code>cimagl</code>, declared in <code>&lt;complex.h&gt;</code> and also provided as
  104. built-in functions by GCC.
  105. </p>
  106. <a name="index-complex-conjugation"></a>
  107. <p>The operator &lsquo;<samp>~</samp>&rsquo; performs complex conjugation when used on a value
  108. with a complex type. This is a GNU extension; for values of
  109. floating type, you should use the ISO C99 functions <code>conjf</code>,
  110. <code>conj</code> and <code>conjl</code>, declared in <code>&lt;complex.h&gt;</code> and also
  111. provided as built-in functions by GCC.
  112. </p>
  113. <p>GCC can allocate complex automatic variables in a noncontiguous
  114. fashion; it&rsquo;s even possible for the real part to be in a register while
  115. the imaginary part is on the stack (or vice versa). Only the DWARF
  116. debug info format can represent this, so use of DWARF is recommended.
  117. If you are using the stabs debug info format, GCC describes a noncontiguous
  118. complex variable as if it were two separate variables of noncomplex type.
  119. If the variable&rsquo;s actual name is <code>foo</code>, the two fictitious
  120. variables are named <code>foo$real</code> and <code>foo$imag</code>. You can
  121. examine and set these two fictitious variables with your debugger.
  122. </p>
  123. <hr>
  124. <div class="header">
  125. <p>
  126. Next: <a href="Floating-Types.html#Floating-Types" accesskey="n" rel="next">Floating Types</a>, Previous: <a href="Long-Long.html#Long-Long" accesskey="p" rel="prev">Long Long</a>, Up: <a href="C-Extensions.html#C-Extensions" accesskey="u" rel="up">C Extensions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  127. </div>
  128. </body>
  129. </html>