
On 03/05/2012 10:41 PM, Matthieu Schaller wrote:
Dear all,
Following the comments from V. Escriba, I formally propose my complex number library for review. The library is an extension of the std::complex class addressing two issues: - The standard does not guaranty the behaviour of the complex class if instantiated with types other than float/double/long double. - Some calculation where pure imaginary numbers (i.e. multiples of sqrt(-1)) appear are unnecessarily slowed down due to the lack of support for these numbers. The code I submit contains two interleaved classes boost::complex and boost::imaginary which can be instantiated with any type T provided T overloads the usual arithmetic operators and some basic (real) mathematical functions depending on which complex function will be used.
How about having a boost::real<T> (or whatever you want to name it), that references a complex number with an imaginary part set to 0? The difference would be that sqrt(boost::real<double>(-1)) would return a boost::complex<T> rather than a NaN.