c/8395: gcc 2.95.4 and 3.2 generate wrong code for double on intel

Bruce Allen ballen@gravity.phys.uwm.edu
Sat Nov 2 22:26:00 GMT 2002


The following reply was made to PR c/8395; it has been noted by GNATS.

From: Bruce Allen <ballen@gravity.phys.uwm.edu>
To: Marco Bernardo <bernardo@sti.uniurb.it>
Cc: Toon Moene <toon@moene.indiv.nluug.nl>, Bruce Allen <ballen@aei.mpg.de>,
       gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
       nobody@gcc.gnu.org
Subject: Re: c/8395: gcc 2.95.4 and 3.2 generate wrong code for double on
 intel
Date: Sun, 3 Nov 2002 00:18:59 -0600 (CST)

 Marco, Toon is completely correct.  
 
 If you read the materials that we keep asking you to study, you will learn
 that there is a discrete set of "IEEE754 floating point numbers".  
 Somewhat less than 2^32 of them for single precision, somewhat less than
 2^64 of them for double precision.
 
 As a consequence, since this is a finite set, and the real numbers are not
 even a countable set, most real numbers are not IEEE754 floats.  Only a
 finite subset are.  Examples:
  Pi      ==> not an IEEE754 float
  1.2     ==> not an IEEE754 float
  6       ==> IS an IEEE754 float
  1.25    ==> IS an IEEE754 float
  1+2^-20 ==> IS an IEEE754 float
 Also, a mathematical operation between two IEEE754 floats may or may not
 yield another IEEE754 float.  For example 1.25*1.25 does yield another
 IEEE754 float, but (1+2^-20)*(1+2^-20) does yield an IEEE754 float if
 working in double precision, but not in single precision.
 
 When the result of a mathematical operation (say, assigning 1.2 to an
 IEEE754 variable) does not yield an IEEE754 float, the standard specifies
 a couple of different possible user-selectable ways to round the number
 (assign it an IEEE754 value).  There is round-to-nearest (pick closest
 IEEE754 float) and round-to-zero.
 
 Also, languages like C do not specify an order for operations to take
 place  in expressions.  So two identical lines of C might yield different
 results with different compilers.
 
 Like you, I am a University Professor (Physics).  I teach IEEE754 in my
 course on mathematical methods where we spend a few weeks on numerical
 methods.  Here are a few exercises for you to do:
 
 -- what is the largest integer that is an IEEE754 single float?  double
    float? Write this as a sum of powers of 2.
 -- what is the largest integer N such that both N and N+1 are IEEE754
    single floats?
 -- what is the smallest positive number that is still a normalized IEEE754
    single float.  smallest positive number that is an IEEE754 single float
    but is not normalized?
 Please read some of the literature (it is not a complicated subject) and
 do the exercises.
 
 Bruce Allen
 
 On Sat, 2 Nov 2002, Toon Moene wrote:
 
 > Marco Bernardo wrote:
 > 
 > > 1. Some colleagues of mine tried to compile and run the same program
 > >    on other platforms, in particular on a sparc machine, and the output
 > >    turned out to be
 > >        -6 -1.2 5 0 -6 0
 > >    Why is that? Isn't the IEEE 754 standard adopted on sparc machines?
 > 
 > Yes.  For further explanations, see the "Further Readings" item on our 
 > home page:
 > 
 > http://gcc.gnu.org -> "Further Readings" (left column) ->
 > 
 > 	Differences among IEEE 754 implementations (by Doug Priest)
 > 
 > -- 
 > Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
 > Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
 > Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
 > Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
 > 
 > 
 



More information about the Gcc-prs mailing list