public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Bruce Allen <ballen@aei.mpg.de> 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: Wed, 30 Oct 2002 09:36:00 -0000 [thread overview] Message-ID: <20021030173604.3606.qmail@sources.redhat.com> (raw) The following reply was made to PR c/8395; it has been noted by GNATS. From: Bruce Allen <ballen@aei.mpg.de> To: gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, bernardo@sti.uniurb.it, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org Cc: Subject: Re: c/8395: gcc 2.95.4 and 3.2 generate wrong code for double on intel Date: Wed, 30 Oct 2002 18:25:15 +0100 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8395 There's nothing wrong here. It's very reasonable for this code to produce ~10^-16 for double. The reason is tha the number 1.2 can not be exactly represented as an IEEE754 floating point number. The numbers 5 and -6 CAN be exactly represented. I suggest that you read the first 15 or so pages of "Numerical Recipes in C" by Press, Teukolsky (and two others). They discuss this question. Then look at http://www.etsimo.uniovi.es/~antonio/uned/ieee754/IEEE-754.html The closest IEEE754 double to 1.2 is (in binary) 1.0011001100110011001100110011001100110011001100110011 = 1.1999999999999999555910790149937383830547332763671875...... in decimal. If we multiply this by 5 (which is exactly represented by an IEEE754 double) one gets 5.9999999999999997779553950749686919152736663818359375 which is not 6. The difference is what you are seeing. #include <stdio.h> int main(void) { double x, y, z; long double lx, ly, lz; x = -6.0; y = -1.2; z = 5; printf("%g %g %g %g\n", x, y, z, x - y * z); lx = -6.0L; ly = -1.2L; lz = 5L; printf("%Lg %Lg %Lg %Lg\n", lx, ly, lz, lx - ly * lz); return(0); }
next reply other threads:[~2002-10-30 17:36 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-10-30 9:36 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 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 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=20021030173604.3606.qmail@sources.redhat.com \ --to=ballen@aei.mpg.de \ --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: linkBe 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).