* Floating point results change with different compilation options
@ 2007-10-23 8:42 Cristea Bogdan
2007-10-23 12:01 ` John Love-Jensen
2007-10-23 17:36 ` burlen
0 siblings, 2 replies; 3+ messages in thread
From: Cristea Bogdan @ 2007-10-23 8:42 UTC (permalink / raw)
To: gcc-help
Hi
I use gcc compiler in order to study the behavior of some iterative
maps (x_n=f(x_{n-1})) using single floating point precision (following
IEEE 754 standard). I have noticed that using different compiler
options, the output sequence could be very different. My programs are
written in C++ using 'float' type and I use 'gcc version 4.1.2
20061115 (prerelease) (Debian 4.1.1-21)'. Compilation options are:
'-Wall -O3 -march=pentium4' or '-Wall'. The same program compiled with
gcc 4.2.2 gives the same results regardless of the compilation options
(on an athlon64 processor).
Is this a bug of the compiler or the floating point representation
differs from one compiler version to the other?
--
Bogdan Cristea
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Floating point results change with different compilation options
2007-10-23 8:42 Floating point results change with different compilation options Cristea Bogdan
@ 2007-10-23 12:01 ` John Love-Jensen
2007-10-23 17:36 ` burlen
1 sibling, 0 replies; 3+ messages in thread
From: John Love-Jensen @ 2007-10-23 12:01 UTC (permalink / raw)
To: Cristea Bogdan, MSX to GCC
Hi Cristea,
> Is this a bug of the compiler...?
No. Certain optimizations can exacerbate code that poorly accommodates
float peculiarities.
> ...or the floating point representation differs from one compiler version to
the other?
No, not the representation. Probably the calculation.
The problem is one-or-both of:
+ not all hardware is compliant with IEEE 754 calculations
+ not all code is written carefully to accommodate float peculiarities
Please read the article What Every Computer Scientist Should Know About
Floating-Point Arithmetic, by David Goldberg (1991).
http://docs.sun.com/source/806-3568/ncg_goldberg.html
HTH,
--Eljay
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Floating point results change with different compilation options
2007-10-23 8:42 Floating point results change with different compilation options Cristea Bogdan
2007-10-23 12:01 ` John Love-Jensen
@ 2007-10-23 17:36 ` burlen
1 sibling, 0 replies; 3+ messages in thread
From: burlen @ 2007-10-23 17:36 UTC (permalink / raw)
To: Cristea Bogdan, gcc-help
Hi,
I think the behavior you described can be expected in some cases. It is
most likely not a difference in floating point representation(thanks to
ieee754). different instruction sequences are expected to produce
different results thanks to rounding errors, especially in your case
where the result is used over and over. the errors grow with each
step!!! (if you haven't seen it before) You have to check out Goldberg
1992 "What every scientist should know about floating point" he shows
you how to estimate an upper bound on the rounding error. The bound
depends on the number and type of and ordering of flops. That is why
different sequences can produce different results. Also for curiosity
sake you might take a close look at the fpu control word, and verify
that the same mode is being used on both builds. Setting the control
word is something that the compiler is responsible for but not part of
the ieee754 standard. It is conceivable(but unlikely) that the FPU is
being configured differently on the two systems. (see Intel "Programming
with the x87 fpu"), specifically the rounding control field.
HTH
--
Burlen Loring
Information Technologist III
Space Science Center
Institute for the Study of Earth, Oceans, and Space
University of New Hampshire
39 College Road, Durham, NH 03824
Phone: 603-862-1140
Cristea Bogdan wrote:
> Hi
> I use gcc compiler in order to study the behavior of some iterative
> maps (x_n=f(x_{n-1})) using single floating point precision (following
> IEEE 754 standard). I have noticed that using different compiler
> options, the output sequence could be very different. My programs are
> written in C++ using 'float' type and I use 'gcc version 4.1.2
> 20061115 (prerelease) (Debian 4.1.1-21)'. Compilation options are:
> '-Wall -O3 -march=pentium4' or '-Wall'. The same program compiled with
> gcc 4.2.2 gives the same results regardless of the compilation options
> (on an athlon64 processor).
> Is this a bug of the compiler or the floating point representation
> differs from one compiler version to the other?
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-10-23 16:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-23 8:42 Floating point results change with different compilation options Cristea Bogdan
2007-10-23 12:01 ` John Love-Jensen
2007-10-23 17:36 ` burlen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).