bigsteve87
asked on
Is it possible to overload the double = (float) operator?
Is it possible to overload the double = operator?
We're having some trouble with calculations in our software because of the issues converting floats to doubles. Nearly all variables are floats but there are thousands of calls to DLLs that require doubles and the slight differences are causing problems.
For Example:
One solution is to convert all our float variables to doubles, but you can imagine how messy that could get.
Maybe I'm barking up the wrong tree and the operator I need to overload is the float () operator to cast it into a double.
I'm not sure if it's even possible. Just wondering if anyone has any brilliant solution for this. I haven't found anything after alot of searching.
We're having some trouble with calculations in our software because of the issues converting floats to doubles. Nearly all variables are floats but there are thousands of calls to DLLs that require doubles and the slight differences are causing problems.
For Example:
float fVal = 7.f;
double val = fVal;
The double ends up coming out to something like 7.00000051351One solution is to convert all our float variables to doubles, but you can imagine how messy that could get.
Maybe I'm barking up the wrong tree and the operator I need to overload is the float () operator to cast it into a double.
I'm not sure if it's even possible. Just wondering if anyone has any brilliant solution for this. I haven't found anything after alot of searching.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you want to change all usage of float to double indiscriminately, it's probably better to do a global find/replace, rather than using a non-intuitive pre-processor macro that is likely to cause a lot of confusion, and will be a maintenance nightmare.
ASKER
I figured there wasn't an easy way around it. A global replace is what needs to be done. Thanks for the help.
#define float double
and reran the program, and still got 7. I didn't prove anything changed. And since I never did this before, I haven't thought of the ramifications. But if it is legit, then you could add this line to a header file that is included everywhere.