public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Marco Bernardo <bernardo@sti.uniurb.it> 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 07:46:00 -0000 [thread overview] Message-ID: <20021102154602.21406.qmail@sources.redhat.com> (raw) The following reply was made to PR c/8395; it has been noted by GNATS. From: Marco Bernardo <bernardo@sti.uniurb.it> To: Bruce Allen <ballen@gravity.phys.uwm.edu> Cc: 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: Sat, 2 Nov 2002 16:42:46 +0100 (CET) On Thu, 31 Oct 2002, Bruce Allen wrote: >It's not an argument, it's simply the facts. Please read the materials >that I refered you to. Ok, let us suppose that for the following program prova.c #include <stdio.h> int main(void) { double x, y, z, y_times_z; x = -6.0; y = -1.2; z = 5; y_times_z = y * z; printf("%g %g %g %g %g %g\n", x, y, z, x - y * z, y_times_z, x - y_times_z); return(0); } compiled with gcc -ansi -Wall prova.c -o prova on an intel machine, the following output -6 -1.2 5 -2.22045e-16 -6 0 ^^^^^^^^^^^^ is not a bug, but simply a consequence of the adoption of the IEEE 754 standard for floating point numbers. Now, I see two problems: 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? 2. I hope we all agree on the fact that the output produced by a (sequential) C program is the same for a given input, regardless of the compilation options that are used. (If not, the compiler would not be compliant with the semantics). Now, try to compile the program above with gcc -ansi -Wall -O prova.c -o prova on an intel machine, i.e. try to set the code optimization option. In such a case the output turns out to be -6 -1.2 5 0 -6 0 i.e. the right value 0 is obtained instead of the wrong -2.22045e-16. This is a clear evidence that gcc contains a serious bug that should be fixed asap (in the right way, i.e. according to the output obtained by setting option -O). Let me conclude by saying that my intention is not to be polemic. My point of view is that of a university professor who wants to teach to his students that there is a great alternative to Microsoft, which is Linux and the free software world. You would then understand that it is very difficult for me to support gcc and to teach my students how to use gcc in the presence of such a strange behavior, which is not justifiable at all on a scientific basis. Best regards, Marco @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Prof. Marco Bernardo Universita` di Urbino Centro per l'Applicazione delle Scienze e Tecnologie dell'Informazione Piazza della Repubblica 13, 61029 Urbino, Italy Phone: +39-0722-4475 - E-mail: bernardo@sti.uniurb.it Fax: +39-0722-4475 - WWW: http://www.sti.uniurb.it/bernardo/ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
next reply other threads:[~2002-11-02 15:46 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-11-02 7:46 Marco Bernardo [this message] -- strict thread matches above, loose matches on Subject: below -- 2002-11-04 9:06 Joseph S. Myers 2002-11-04 9:06 Marco Bernardo 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-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=20021102154602.21406.qmail@sources.redhat.com \ --to=bernardo@sti.uniurb.it \ --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).