From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/numeric%2Fcomplex%2Fi.html | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 devdocs/c/numeric%2Fcomplex%2Fi.html (limited to 'devdocs/c/numeric%2Fcomplex%2Fi.html') diff --git a/devdocs/c/numeric%2Fcomplex%2Fi.html b/devdocs/c/numeric%2Fcomplex%2Fi.html new file mode 100644 index 00000000..d1d3f90d --- /dev/null +++ b/devdocs/c/numeric%2Fcomplex%2Fi.html @@ -0,0 +1,45 @@ +

I

Defined in header <complex.h>
#define I /* unspecified */
+
(since C99)

The I macro expands to either _Complex_I or _Imaginary_I. If the implementation does not support imaginary types, then the macro always expands to _Complex_I.

+

A program may undefine and perhaps then redefine the macro I.

+

Notes

The macro is not named i, which is the name of the imaginary unit in mathematics, because the name i was already used in many C programs, e.g. as a loop counter variable.

+

The macro I is often used to form complex numbers, with expressions such as x + y*I. If I is defined as _Complex_I, then such expression may create a value with imaginary component +0.0 even when y is -0.0, which is significant for complex number functions with branch cuts. The macro CMPLX provides a way to construct a complex number precisely.

+

GCC provides a non-portable extension that allows imaginary constants to be specified with the suffix i on integer literals: 1.0fi, 1.0i, and 1.0li are imaginary units in GNU C. A similar approach is part of standard C++ as of C++14 (1.0if, 1.0i, and 1.0il are the imaginary units in C++)

+

Example

#include <stdio.h>
+#include <complex.h>
+ 
+int main(void)
+{
+    printf("I = %.1f%+.1fi\n", creal(I), cimag(I));
+ 
+    double complex z1 = I * I;     // imaginary unit squared
+    printf("I * I = %.1f%+.1fi\n", creal(z1), cimag(z1));
+ 
+    double complex z = 1.0 + 2.0*I; // usual way to form a complex number pre-C11
+    printf("z = %.1f%+.1fi\n", creal(z), cimag(z));
+}

Output:

+
I = 0.0+1.0i
+I * I = -1.0+0.0i
+z = 1.0+2.0i

References

See also

+ + + +
+
(C99)
the imaginary unit constant i
(macro constant)
+
(C99)
the complex unit constant i
(macro constant)
+
(C11)(C11)(C11)
constructs a complex number from real and imaginary parts
(function macro)
C++ documentation for operator""i
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/numeric/complex/I +

+
-- cgit v1.2.3