Ron Johnson <[EMAIL PROTECTED]> writes:
> Out of curiosity: why does -ffast-math break the datetime rounding code?

We dug into this last night, and it turns out that the culprit is code
like

        int hour = time / 3600;

where time is a double.  This yields an exact result when done
correctly, but with -ffast-math gcc will "improve" it to

        int hour = time * 0.000277777777777778;

the constant being the nearest double value to 1.0 / 3600.0.  The
problem is that the constant is inexact and in fact is slightly too
large; so for example if time is exactly 18000.0, you get a resulting
hour value of 4, not 5, after truncation to integer.  Repeated a couple
more times, what should have been 5:00:00 comes out as 4:59:60 ...

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly

Reply via email to