digitalmars.D.bugs - Implicit conversion from complex to real
Should this really be allowed? creal c = 3 + 5i; double d = c; // d is now 3 Besides being a lossy conversion, it can make it difficult to write a complex math library, and lead to some silent bugs if there ever comes to BE a library. For example: creal exp(creal); real exp(real); .. cdouble d = 3 + 4i; exp(d); // The compiler chokes on this one, so we can't overload names Another example: If we rename the complex functions (as done in C99) we get real exp(real); creal cexp(creal); .. creal d = 2i; exp(d); // Typo, should be cexp, but the compiler accepts and exp returns the wrong answer. Nick
Aug 01 2004
"Nick" <Nick_member pathlink.com> wrote in message news:cejsno$2g2s$1 digitaldaemon.com...Should this really be allowed? creal c = 3 + 5i; double d = c; // d is now 3 Besides being a lossy conversion, it can make it difficult to write a complex math library, and lead to some silent bugs if there ever comes to BE a library.Should require explicit cast IMOFor example: creal exp(creal); real exp(real); .. cdouble d = 3 + 4i; exp(d); // The compiler chokes on this one, so we can't overload names Another example: If we rename the complex functions (as done in C99) we get real exp(real); creal cexp(creal); .. creal d = 2i; exp(d); // Typo, should be cexp, but the compiler accepts and exp returns the wrong answer. Nick
Aug 01 2004