While testing some mixed floating point and integer calculations I found a
quite surprising difference when this compiler option was set (gcc 6.x). It was
clearly different at only 100 iterations and got dramatically worse with
larger counts.
My test routine was this:
int a = 0;
float b = 0;
float c = 0;
float inc = 0.1f;
float dec = 0.05f;
int it = 100;
for (int i = 0; i < it; ++ i)
{
a = (int)truncf(b);
c = b - floorf(b);
b += inc;
a = (int)truncf(b);
c = b - floorf(b);
b -= dec;
}
cout << "int " << a << " rem " << c <<
endl;
My suspicion is that the difference is due to accumulated rounding errors.
Curiously without the decrements the behavior with and without -ffast-math
seems to be identical well into the millions.
--
Will J Godfrey
http://www.musically.me.uk
Say you have a poem and I have a tune.
Exchange them and we can both have a poem, a tune, and a song.