Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      From cppreference.com
      <c‎ |numeric‎ |complex
       
       
       
      Complex number arithmetic
      Types and the imaginary constant
      (C99)
      (C99)    
      (C11)
      I
      (C99)
      Manipulation
      (C99)
      (C99)
      (C99)
      (C99)
      (C99)
      (C99)
      Power and exponential functions
      (C99)
      (C99)
      (C99)
      (C99)
      Trigonometric functions
      (C99)
      (C99)
      (C99)
      (C99)
      (C99)
      (C99)
      Hyperbolic functions
      (C99)
      (C99)
      (C99)
      (C99)
      (C99)
      (C99)
       
      Defined in header<complex.h>
      #define I /* unspecified */
      (since C99)

      TheI 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 macroI.

      Contents

      [edit]Notes

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

      The macroI is often used to form complex numbers, with expressions such asx+ y*I. IfI is defined as_Complex_I, then such expression may create a value with imaginary component+0.0 even wheny is-0.0, which is significant for complex number functions with branch cuts. The macroCMPLX provides a way to construct a complex number precisely.

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

      [edit]Example

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

      Output:

      I = 0.0+1.0iI * I = -1.0+0.0iz = 1.0+2.0i

      [edit]References

      • C11 standard (ISO/IEC 9899:2011):
      • 7.3.1/6 I (p: 188)
      • G.6/1 I (p: 537)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.3.1/4 I (p: 170)
      • G.6/1 I (p: 472)

      [edit]See also

      the imaginary unit constant i
      (macro constant)[edit]
      the complex unit constant i
      (macro constant)[edit]
      (C11)(C11)(C11)
      constructs a complex number from real and imaginary parts
      (function macro)[edit]
      C++ documentation foroperator""i
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/numeric/complex/I&oldid=77426"

      [8]ページ先頭

      ©2009-2025 Movatter.jp