|
-
December 4th, 2008, 02:33 PM
#1
compiler errors using complex<float> in C++
I usually work with complex data. When they changed the complex data class to use templates, they broke most of the code I had written until then. I was able to fix errors like in line 1 by making sure the constant was real, instead of an integer, as in line 2. An annoyance, but not too horrible.
At the time, I converted all my code to use complex<double> because that is essentially what the original complex had been, and have been using complex<double> since. I have a code that will need to work with very large data sets, so I need to use complex<float> instead. And now I get compile time errors for lines like 3 and 4. Is some way to allow a literal constant times a complex<float> to compile (without littering my code with a bunch of casts, like in line 5)?
I'm using MS Visual Studio 2008 Standard Edition, if there's some compiler-specific flag that will fix this.
Code:
#include <complex>
using namespace std;
int dumdum(const complex<float> &cf, const complex<double> &cd)
{
complex<double> cd0;
complex<float> cf0;
cd0 = 2 * cd; // 1. Error. Easy work-around: use 2.0
cd0 = 2.0 * cd; // 2. No error.
cf0 = 3.0 * cf; // 3. An error? Are you kidding me????
cf0 = cf * 3.0; // 4. Still an error.
cf0 = cf * (float)3.0; // 5. Kludge. And ugly.
return 0;
}
-
December 4th, 2008, 03:05 PM
#2
Re: compiler errors using complex<float> in C++
-
December 4th, 2008, 03:06 PM
#3
Re: compiler errors using complex<float> in C++
Code:
cf0 = 3.0f * cf;
cf0 = cf * 3.0f;
3.0 is interpreted as a double, until you add the f-postfix.
Last edited by laitinen; December 4th, 2008 at 03:08 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|