I know what imaginary and complex numbers are in the math world but what about in C++, what are data types of complex and imaginary. In addition, I see data types such as _Imaginary and _Complex. What is the difference and what are complex and imaginary data types?
Share
_Imaginaryand_Complexare keywords in the C99 language standard used for defining imaginary and complex floating-point variable types; they are not part of the C++ language. They are not data types in and of themselves — they modify thefloat,doubleandlong doubletypes. For example:_Imaginaryvalues are mostly equivalent to regular real values, except when you add a real with an imaginary value, you get a_Complexvalue.The header file
<complex.h>defines the macrosimaginaryas_Imaginaryandcomplexas_Complex, as well asIas either_Complex_Ior_Imaginary_I(the imaginary unit). This is so that legacy C programs can usecomplexandimaginaryas identifiers; new programs should usecomplexandimaginaryinstead of_Complexand_Imaginary. Note that identifiers beginning with an underscore followed by an uppercase letter are reserved by the implementation, so legacy code should never use_Complexor_Imaginary.C++, on the other hand, does not use this, and instead has the templated types
std::complex<float>,std::complex<double>, andstd::complex<long double>for dealing with complex numbers. Those classes function very similarly to the C99 types but are non-interchangeable.