If the macro constant __STDC_NO_COMPLEX__
is defined by the implementation, the complex types, the header <complex.h> and all of the names listed here are not provided.
The C programming language, as of C99, supports complex number math with the three built-in types double _Complex, float _Complex, and long double _Complex (see _Complex). When the header <complex.h> is included, the three complex number types are also accessible as double complex, float complex, long double complex.
In addition to the complex types, the three imaginary types may be supported: double _Imaginary, float _Imaginary, and long double _Imaginary (see _Imaginary). When the header <complex.h> is included, the three imaginary types are also accessible as double imaginary, float imaginary, and long double imaginary.
Standard arithmetic operators +, -, *, / can be used with real, complex, and imaginary types in any combination.
A compiler that defines __STDC_IEC_559_COMPLEX__
is recommended, but not required to support imaginary numbers. POSIX recommends checking if the macro _Imaginary_I is defined to identify imaginary number support.
Imaginary numbers are supported if __STDC_IEC_559_COMPLEX__
or __STDC_IEC_60559_COMPLEX__
(since C23) is defined.
The following function names are potentially(since C23) reserved for future addition to <complex.h> and are not available for use in the programs that include that header: cerf, cerfc, cexp2, cexpm1, clog10, clog1p, clog2, clgamma, ctgamma, csinpi, ccospi, ctanpi, casinpi, cacospi, catanpi, ccompoundn, cpown, cpowr, crootn, crsqrt, cexp10m1, cexp10, cexp2m1, clog10p1, clog2p1, clogp1(since C23), along with their -f
and -l
suffixed variants.
Although the C standard names the inverse hyperbolic with "complex arc hyperbolic sine" etc., the inverse functions of the hyperbolic functions are the area functions. Their argument is the area of a hyperbolic sector, not an arc. The correct names are "complex inverse hyperbolic sine" etc. Some authors use "complex area hyperbolic sine" etc.
A complex or imaginary number is infinite if one of its parts is infinite, even if the other part is NaN.
A complex or imaginary number is finite if both parts are neither infinities nor NaNs.
A complex or imaginary number is a zero if both parts are positive or negative zeroes.
While MSVC does provide a <complex.h>
header, it does not implement complex numbers as native types, but as structs, which are incompatible with standard C complex types and do not support the +, -, *, / operators.
#include <complex.h> #include <stdio.h> #include <tgmath.h> int main(void) { double complex z1 = I * I; // imaginary unit squared printf("I * I = %.1f%+.1fi\n", creal(z1), cimag(z1)); double complex z2 = pow(I, 2); // imaginary unit squared printf("pow(I, 2) = %.1f%+.1fi\n", creal(z2), cimag(z2)); double PI = acos(-1); double complex z3 = exp(I * PI); // Euler's formula printf("exp(I*PI) = %.1f%+.1fi\n", creal(z3), cimag(z3)); double complex z4 = 1 + 2 * I, z5 = 1 - 2 * I; // conjugates printf("(1+2i)*(1-2i) = %.1f%+.1fi\n", creal(z4 * z5), cimag(z4 * z5)); }
Output:
I * I = -1.0+0.0i pow(I, 2) = -1.0+0.0i exp(I*PI) = -1.0+0.0i (1+2i)*(1-2i) = 5.0+0.0i[edit] References Extended content
__STDC_NO_COMPLEX__
(p: TBD)__STDC_IEC_559_COMPLEX__
(p: TBD)<complex.h>
(p: TBD)<tgmath.h>
(p: TBD)<complex.h>
(p: TBD)__STDC_NO_COMPLEX__
(p: 128)__STDC_IEC_559_COMPLEX__
(p: 128)<complex.h>
(p: 136-144)<tgmath.h>
(p: 272-273)<complex.h>
(p: 391)__STDC_NO_COMPLEX__
(p: 177)__STDC_IEC_559_COMPLEX__
(p: 177)<complex.h>
(p: 188-199)<tgmath.h>
(p: 373-375)<complex.h>
(p: 455)__STDC_IEC_559_COMPLEX__
(p: 161)<complex.h>
(p: 170-180)<tgmath.h>
(p: 335-337)<complex.h>
(p: 401)RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4