You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
7.3KB

  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-2020 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 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Complex (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Complex (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Complex (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  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.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Complex"></a>
  62. <div class="header">
  63. <p>
  64. 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>
  65. </div>
  66. <hr>
  67. <a name="Complex-Numbers"></a>
  68. <h3 class="section">6.11 Complex Numbers</h3>
  69. <a name="index-complex-numbers"></a>
  70. <a name="index-_005fComplex-keyword"></a>
  71. <a name="index-_005f_005fcomplex_005f_005f-keyword"></a>
  72. <p>ISO C99 supports complex floating data types, and as an extension GCC
  73. supports them in C90 mode and in C++. GCC also supports complex integer data
  74. types which are not part of ISO C99. You can declare complex types
  75. using the keyword <code>_Complex</code>. As an extension, the older GNU
  76. keyword <code>__complex__</code> is also supported.
  77. </p>
  78. <p>For example, &lsquo;<samp>_Complex double x;</samp>&rsquo; declares <code>x</code> as a
  79. variable whose real part and imaginary part are both of type
  80. <code>double</code>. &lsquo;<samp>_Complex short int y;</samp>&rsquo; declares <code>y</code> to
  81. have real and imaginary parts of type <code>short int</code>; this is not
  82. likely to be useful, but it shows that the set of complex types is
  83. complete.
  84. </p>
  85. <p>To write a constant with a complex data type, use the suffix &lsquo;<samp>i</samp>&rsquo; or
  86. &lsquo;<samp>j</samp>&rsquo; (either one; they are equivalent). For example, <code>2.5fi</code>
  87. has type <code>_Complex float</code> and <code>3i</code> has type
  88. <code>_Complex int</code>. Such a constant always has a pure imaginary
  89. value, but you can form any complex value you like by adding one to a
  90. real constant. This is a GNU extension; if you have an ISO C99
  91. conforming C library (such as the GNU C Library), and want to construct complex
  92. constants of floating type, you should include <code>&lt;complex.h&gt;</code> and
  93. use the macros <code>I</code> or <code>_Complex_I</code> instead.
  94. </p>
  95. <p>The ISO C++14 library also defines the &lsquo;<samp>i</samp>&rsquo; suffix, so C++14 code
  96. that includes the &lsquo;<samp>&lt;complex&gt;</samp>&rsquo; header cannot use &lsquo;<samp>i</samp>&rsquo; for the
  97. GNU extension. The &lsquo;<samp>j</samp>&rsquo; suffix still has the GNU meaning.
  98. </p>
  99. <a name="index-_005f_005freal_005f_005f-keyword"></a>
  100. <a name="index-_005f_005fimag_005f_005f-keyword"></a>
  101. <p>To extract the real part of a complex-valued expression <var>exp</var>, write
  102. <code>__real__ <var>exp</var></code>. Likewise, use <code>__imag__</code> to
  103. extract the imaginary part. This is a GNU extension; for values of
  104. floating type, you should use the ISO C99 functions <code>crealf</code>,
  105. <code>creal</code>, <code>creall</code>, <code>cimagf</code>, <code>cimag</code> and
  106. <code>cimagl</code>, declared in <code>&lt;complex.h&gt;</code> and also provided as
  107. built-in functions by GCC.
  108. </p>
  109. <a name="index-complex-conjugation"></a>
  110. <p>The operator &lsquo;<samp>~</samp>&rsquo; performs complex conjugation when used on a value
  111. with a complex type. This is a GNU extension; for values of
  112. floating type, you should use the ISO C99 functions <code>conjf</code>,
  113. <code>conj</code> and <code>conjl</code>, declared in <code>&lt;complex.h&gt;</code> and also
  114. provided as built-in functions by GCC.
  115. </p>
  116. <p>GCC can allocate complex automatic variables in a noncontiguous
  117. fashion; it&rsquo;s even possible for the real part to be in a register while
  118. the imaginary part is on the stack (or vice versa). Only the DWARF
  119. debug info format can represent this, so use of DWARF is recommended.
  120. If you are using the stabs debug info format, GCC describes a noncontiguous
  121. complex variable as if it were two separate variables of noncomplex type.
  122. If the variable&rsquo;s actual name is <code>foo</code>, the two fictitious
  123. variables are named <code>foo$real</code> and <code>foo$imag</code>. You can
  124. examine and set these two fictitious variables with your debugger.
  125. </p>
  126. <hr>
  127. <div class="header">
  128. <p>
  129. 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>
  130. </div>
  131. </body>
  132. </html>