This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
On 23 January 2013 10:21, Marc Glisse <marc.glisse@inria.fr> wrote:Here is what [cmplx.over] says:
"Function template pow shall have additional overloads sufficient to ensure, for a call with at least one argument of type complex<T>: 1. If either argument has type complex<long double> or type long double, then both arguments are effectively cast to complex<long double>. 2. Otherwise, if either argument has type complex<double>, double, or an integer type, then both arguments are effectively cast to complex<double>. 3. Otherwise, if either argument has type complex<float> or float, then both arguments are effectively cast to complex<float>."
So it looks like we are forced to convert 2 to a complex<double> and then call pow on that.
I am not very good at reading standardese, but what does "effectively cast" mean here?
Maybe the libm function doesn't round well then?
If you have floats or doubles as your type, I don't think you can avoid the rounding error.
It seems to me that having the int overload, truncating its precision if necessary, and then performing computations with integers (e.g. by binary exponentiation), should not break anything else.
-- Marc Glisse
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |