[Proj] Re: Re: Re: Proj4 Bug (rtodms)
glynn at gclements.plus.com
Sat Nov 11 04:52:09 EST 2006
Gerald I. Evenden wrote:
> I threw caution to the winds and did:
> gcc -funsafe-math-optimizations -O3 sample2.c -lm
> gcc -ffast-math -O3 sample2.c -lm
> and I still cannot fail the test. My compiler practices safe sex, er safe
> floating point regardless of what I tell it. It must have a permanently
> attached condom.
On the contrary, it's practicing *unsafe* floating point.
According to the IEEE FP and ANSI C standards, the test *should* fail,
as 240.0*(1.0/60.0) is less than 4.0 at double precision, and thus
rounding to an integer towards either negative infinity (for floor())
or zero (for an integer type cast) should give 3.
It is greater than 4.0 at extended precision, but you haven't asked
for that. The variables are all declared as "double" and FP literals
are interpreted as double unless declared otherwise (with a trailing
"f" for single precision or a trailing "L" for extended precision).
Also, -funsafe-math-optimizations probably won't have any effect here,
as the test program makes the unsafe optimisation itself. However, it
may cause (240.0/60.0) to also suffer from rounding error by
"optimising" (i.e. approximating) it to 240.0*(1.0/60.0).
While discussion of precision and rounding is all very interesting,
let's not forget that the real problem here is that the compiler is
converting division to multiplication by the reciprocal (an unsafe
optimisation) in the first place, not how the "optimised" form is
Glynn Clements <glynn at gclements.plus.com>
More information about the Proj