summaryrefslogtreecommitdiff
path: root/devdocs/c/numeric%2Fcomplex%2Fcomplex_i.html
blob: 9ccc4b52a01eebb989f06ef2988004cb4ce4d533 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    <h1 id="firstHeading" class="firstHeading">_Complex_I</h1>            <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;complex.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define _Complex_I /* unspecified */</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr>  </table> <p>The <code>_Complex_I</code> macro expands to a value of type <code>const float _Complex</code> with the value of the imaginary unit.</p>
<h3 id="Notes"> Notes</h3> <p>This macro may be used when <code>I</code> is not available, such as when it has been undefined by the application.</p>
<p>Unlike <code><a href="imaginary_i" title="c/numeric/complex/Imaginary I">_Imaginary_I</a></code> and <code><a href="cmplx" title="c/numeric/complex/CMPLX">CMPLX</a></code>, use of this macro to construct a complex number may lose the sign of zero on the imaginary part.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;stdio.h&gt;
#include &lt;complex.h&gt;
 
#undef I
#define J _Complex_I // can be used to redefine I
 
int main(void)
{
    // can be used to construct a complex number
    double complex z = 1.0 + 2.0 * _Complex_I;
    printf("1.0 + 2.0 * _Complex_I = %.1f%+.1fi\n", creal(z), cimag(z));
 
    // sign of zero may not be preserved
    double complex z2 = 0.0 + -0.0 * _Complex_I;
    printf("0.0 + -0.0 * _Complex_I = %.1f%+.1fi\n", creal(z2), cimag(z2));
}</pre></div> <p>Possible output:</p>
<div class="text source-text"><pre data-language="c">1.0 + 2.0 * _Complex_I = 1.0+2.0i
0.0 + -0.0 * _Complex_I = 0.0+0.0i</pre></div> </div> <h3 id="References"> References</h3>  <ul>
<li> C23 standard (ISO/IEC 9899:2023): </li>
<ul><li> 7.3.1/4 _Complex_I (p: TBD) </li></ul>
<li> C17 standard (ISO/IEC 9899:2018): </li>
<ul><li> 7.3.1/4 _Complex_I (p: 136) </li></ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.3.1/4 _Complex_I (p: 188) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.3.1/2 _Complex_I (p: 170) </li></ul>
</ul>               <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="imaginary_i" title="c/numeric/complex/Imaginary I"> <span class="t-lines"><span>_Imaginary_I</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> the imaginary unit constant i <br> <span class="t-mark">(macro constant)</span>  </td>
</tr> <tr class="t-dsc"> <td> <div><a href="i" title="c/numeric/complex/I"> <span class="t-lines"><span>I</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> the complex or imaginary unit constant i <br> <span class="t-mark">(macro constant)</span>  </td>
</tr> </table>           <div class="_attribution">
  <p class="_attribution-p">
    &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
    <a href="https://en.cppreference.com/w/c/numeric/complex/Complex_I" class="_attribution-link">https://en.cppreference.com/w/c/numeric/complex/Complex_I</a>
  </p>
</div>