Kevin Manuele
2008-05-20 20:44:49 UTC
This might be an IDE question, but we have a problem that is stumping us.
We have a custom Complex_ class in a library that provides basic complex
math functions. It includes some unary overloaded member operators. In the
same library are some global binary operators.
In our application, we were finding strange numerical errors, so we put the
following simple test code in the app.
Complex_ xx(2,3);
Complex_ yy(-2, -8);
Complex_ ww = xx;
ww *= yy; // member operator
ww = 0.0; // clear values
ww = xx * yy; // global binary operator
When we run it, the unary member operator gives the correct answer, but the
global operator does not. The real value is correct, but the imag is not.
We can trace into the library with the debugger, and it traces into the
constructors and assignment operators, but not into the global operator code
nor the member code. It is clearly doing some math --- but where?
Strangely, when we put the identical test code, linked to the same library,
in a simple "clean" app, it runs correctly, and we can trace into the global
operator code just as we expected.
Finally, if we create the same global operator without the 'const' args, it
works ok correctly in our app.
We have re-built our app, and all the libraries, from the ground up several
times and cannot resolve this problem.
The global code is simple, and uses the member unary operator
Complex_ operator* (const Complex_& c, const Complex_& d)
{
Complex_ x = c;
x *= d;
return x;
}
The member function is simple also:
class Complex_
{
public:
double real, imag;
...
...
Complex_& operator*= (const Complex_& c)
{
double ac = real * c.real;
double bd = imag * c.imag;
imag = ((real + imag) * (c.real + c.imag)) - ac - bd;
real = ac - bd;
return *this;
}
};
Any ideas ???
Thanks
Kevin
We have a custom Complex_ class in a library that provides basic complex
math functions. It includes some unary overloaded member operators. In the
same library are some global binary operators.
In our application, we were finding strange numerical errors, so we put the
following simple test code in the app.
Complex_ xx(2,3);
Complex_ yy(-2, -8);
Complex_ ww = xx;
ww *= yy; // member operator
ww = 0.0; // clear values
ww = xx * yy; // global binary operator
When we run it, the unary member operator gives the correct answer, but the
global operator does not. The real value is correct, but the imag is not.
We can trace into the library with the debugger, and it traces into the
constructors and assignment operators, but not into the global operator code
nor the member code. It is clearly doing some math --- but where?
Strangely, when we put the identical test code, linked to the same library,
in a simple "clean" app, it runs correctly, and we can trace into the global
operator code just as we expected.
Finally, if we create the same global operator without the 'const' args, it
works ok correctly in our app.
We have re-built our app, and all the libraries, from the ground up several
times and cannot resolve this problem.
The global code is simple, and uses the member unary operator
Complex_ operator* (const Complex_& c, const Complex_& d)
{
Complex_ x = c;
x *= d;
return x;
}
The member function is simple also:
class Complex_
{
public:
double real, imag;
...
...
Complex_& operator*= (const Complex_& c)
{
double ac = real * c.real;
double bd = imag * c.imag;
imag = ((real + imag) * (c.real + c.imag)) - ac - bd;
real = ac - bd;
return *this;
}
};
Any ideas ???
Thanks
Kevin