Here is the code:
#define MIN_RESOLUTION ( 0.0000001)
double yMax, yMin;
// calculate yMax, yMin
//....
if( fabs( yMax - yMin) > MIN_RESOLUTION)
{
scaleMin = yMin;
scaleMax = yMax;
}
else
{
// following two lines are executing
scaleMin = yMin - 1.0;
scaleMax = yMax + 1.0;
// could still be the same...
if(scaleMin == scaleMax)
{
if(scaleMax > 0) // decrease min
scaleMin = 0;
else // increase max
scaleMax = 0;
}
}
assert(scaleMin != scaleMax);
In my example yMin == yMax == 1.6170737412027187 e17
. Because of that, the lines 14 and 15 are allways executed:
scaleMin = yMin - 1.0;
scaleMax = yMax + 1.0;
I understand that the precision of double is limited (15 digits) and that the operations of adding / subtracting 1 do not make much sense for such big numbers. But I would expect that the “==” operation always gives ‘true’ then as result. And this is not the case.
Sometimes it happens that the two doubles in the line 18 are not equal (scaleMin == scaleMax) and several lines later they are equal (i.e. assert in the line 27 is triggered). The numbers are allways the same (1.6170737412027187 e17)
I’ve also tried to replace line (27) with this:
if (scaleMin == scaleMax)
{
assert(false);
}
The behavior is still the same. Any ideas?