public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Bruce Allen <ballen@gravity.phys.uwm.edu>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: c/8395: gcc 2.95.4 and 3.2 generate wrong code for double on intel
Date: Sat, 02 Nov 2002 22:26:00 -0000	[thread overview]
Message-ID: <20021103062601.2628.qmail@sources.redhat.com> (raw)

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)
 > 
 > 
 


             reply	other threads:[~2002-11-03  6:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-02 22:26 Bruce Allen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-11-04  9:06 Marco Bernardo
2002-11-04  9:06 Joseph S. Myers
2002-11-04  3:06 Bruce Allen
2002-11-02 22:26 Bruce Allen
2002-11-02  8:26 Tim Prince
2002-11-02  7:56 Toon Moene
2002-11-02  7:46 Marco Bernardo
2002-10-31  0:56 Bruce Allen
2002-10-31  0:46 Marco Bernardo
2002-10-30 12:57 bangerth
2002-10-30  9:36 Bruce Allen
2002-10-30  0:26 bernardo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021103062601.2628.qmail@sources.redhat.com \
    --to=ballen@gravity.phys.uwm.edu \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).