public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Tim Prince <timothyprince@sbcglobal.net> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, Subject: Re: other/10417: Inconsistent results in floating point comparison. Date: Wed, 16 Apr 2003 04:56:00 -0000 [thread overview] Message-ID: <20030416045601.24003.qmail@sources.redhat.com> (raw) The following reply was made to PR other/10417; it has been noted by GNATS. From: Tim Prince <timothyprince@sbcglobal.net> To: csk@mud.cgl.uwaterloo.ca, gcc-gnats@gcc.gnu.org Cc: Subject: Re: other/10417: Inconsistent results in floating point comparison. Date: Tue, 15 Apr 2003 20:36:32 -0700 On Tuesday 15 April 2003 12:01, csk@mud.cgl.uwaterloo.ca wrote: > >Number: 10417 > >Category: other > >Synopsis: Inconsistent results in floating point comparison. > >Environment: > > Debian Woody, Pentium IV > > >Description: > > Witness the following short program: > > --------------------- > #include <stdio.h> > #include <stdlib.h> > > int main( int argc, char ** argv ) > { > double x = atof( argv[1] ); > double d = x*x; > > printf( "%d\n", (x*x<d) ); > return 0; > } > ----------------------- > > Ideally, this program should always print 0, since a number shouldn't be > strictly less than itself. When compiled without optimization, the program > will print 0 or 1 depending on the input (I get 0.3 --> 0, 0.4 --> 1, for > instance). > > Now I understand that floating point numbers are far from ideal, and that > this behaviour might not be a bug. Still, I would love to be able to > characterize for which numbers the program will print 0 or 1. Any > thoughts? If you ask the compiler to generate x87 code (the probable default for your configuration), it could interpret the expression as (long double)x*x < d; so the expression would be 1 every time d has been rounded up. If you use the command gcc -march=pentium4 -mfpmath=sse *.c as you might normally do for a P4, I doubt you could get the results you mention. > > Moreover, the program always prints a 0 when compiled with optimization. > This inconsistency relative to the unoptimized version might indeed > constitute a bug. I can't reproduce this, unless I tell the compiler to generate x87 code. As I don't "always" do that, I am not reproducing your claim. > > -- Tim Prince
next reply other threads:[~2003-04-16 4:56 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2003-04-16 4:56 Tim Prince [this message] -- strict thread matches above, loose matches on Subject: below -- 2003-04-16 14:46 Craig S. Kaplan 2003-04-16 7:30 ebotcazou 2003-04-15 19:06 csk
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=20030416045601.24003.qmail@sources.redhat.com \ --to=timothyprince@sbcglobal.net \ --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).