D
Dilip
Recently in our code, I ran into a situation where were stuffing a
float inside a double. The precision was extended automatically
because of that. To make a long story short, this caused problems
elsewhere in another part of the system where that figure was used for
some calculation and some eventual truncation led to the system going
haywire. So my question is, given this code:
int main()
{
float f = 59.89F;
/* the following line caused problems */
double d = f;
/* they ended up solving it like this */
f *= 1000.0;
double dd = (double)f / 1000.0;
return 0;
}
I see what is being done but why does the latter make the situation
better?
(consider 'f' in real life to hold stock prices)
float inside a double. The precision was extended automatically
because of that. To make a long story short, this caused problems
elsewhere in another part of the system where that figure was used for
some calculation and some eventual truncation led to the system going
haywire. So my question is, given this code:
int main()
{
float f = 59.89F;
/* the following line caused problems */
double d = f;
/* they ended up solving it like this */
f *= 1000.0;
double dd = (double)f / 1000.0;
return 0;
}
I see what is being done but why does the latter make the situation
better?
(consider 'f' in real life to hold stock prices)