K
Kürþat
Hi,
I have a strange problem about a simple sum operation on a double variable.
There is a loop in my application like this :
double _max = 0.4;
double _step = 0.1;
for (double d = 0.0; i < _max || double_equal (i, _max); i += step)
{
// Do something...
}
double_equal() is an epsilon based equality test function.
The problem is i's value on 4. turn. When I watch I see 0.30000000000000004
insted of 0.3
This is problematic because I compare it some other doubles in the loop but
even epsilon based approximitation will fail in this case.
It is interesting that this only appears on loop's 4. turn. On 5.turn the
value is 0.4, excellent!
What is the reason and how can I overcome this?
Thanks in advance.
I have a strange problem about a simple sum operation on a double variable.
There is a loop in my application like this :
double _max = 0.4;
double _step = 0.1;
for (double d = 0.0; i < _max || double_equal (i, _max); i += step)
{
// Do something...
}
double_equal() is an epsilon based equality test function.
The problem is i's value on 4. turn. When I watch I see 0.30000000000000004
insted of 0.3
This is problematic because I compare it some other doubles in the loop but
even epsilon based approximitation will fail in this case.
It is interesting that this only appears on loop's 4. turn. On 5.turn the
value is 0.4, excellent!
What is the reason and how can I overcome this?
Thanks in advance.