I'm wondering what is the "best practice" to define the complex constant "i" in C++.
I know that the "#define
vs const
in C++" question has been asked multiple times, and that the general answer is that it's best to use const.
However, I'm thinking that it makes sense to use #define
instead of const
to define mathematical constants (such as "i" or "pi"), because we don't think of them as variables, but "absolute constants" (in the accepted answer here, one can read: "A constant defined with the const qualifier is best thought of as an unmodifiable variable."). Also, I see that in the math.h
library, constants are defined this way, e.g. #define M_E 2.71828182845904523536028747135266250 /* e */
.
So I'm wondering, how do C++ programmers usually define the complex constant i?
Lastly, I have a small issue with my current code #define I std::complex<double>(0.0, 1.0)
: precompilation causes a name clash with a Qt library that I use (as soon as I enable C++11 support).