blob: 9ca58d2cf9e2ed6a6b85c0925cb8369963cf388c (
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
|
<h1 id="firstHeading" class="firstHeading">complex</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><complex.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define complex _Complex</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> </table> <p>This macro expands to a type specifier used to identify <a href="../../language/arithmetic_types#Complex_floating_types" title="c/language/arithmetic types">complex types</a>.</p>
<p>A program may undefine and perhaps then redefine the <code>complex</code> macro.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h>
#include <complex.h>
#include <math.h>
void print_complex(const char* note, complex z)
{
printf("%s %f%+f*i\n", note, creal(z), cimag(z));
}
int main(void)
{
double complex z = -1.0 + 2.0*I;
print_complex("z =", z);
print_complex("z\u00B2 =", z * z);
double complex z2 = ccos(2.0 * carg(z)) + csin(2.0 * carg(z))*I;
print_complex("z\u00B2 =", cabs(z) * cabs(z) * z2);
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">z = -1.000000+2.000000*i
z² = -3.000000-4.000000*i
z² = -3.000000-4.000000*i</pre></div> </div> <h3 id="References"> References</h3> <ul>
<li> C17 standard (ISO/IEC 9899:2018): </li>
<ul><li> 7.3.1/4 complex (p: 136) </li></ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.3.1/4 complex (p: 188) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.3.1/2 complex (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" title="c/numeric/complex/imaginary"> <span class="t-lines"><span>imaginary</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> imaginary type macro <br> <span class="t-mark">(keyword macro)</span> </td>
</tr> </table> <div class="_attribution">
<p class="_attribution-p">
© 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" class="_attribution-link">https://en.cppreference.com/w/c/numeric/complex/complex</a>
</p>
</div>
|