From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3761 invoked by alias); 30 Oct 2002 17:36:07 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 3635 invoked by uid 71); 30 Oct 2002 17:36:04 -0000 Date: Wed, 30 Oct 2002 09:36:00 -0000 Message-ID: <20021030173604.3606.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Bruce Allen Subject: Re: c/8395: gcc 2.95.4 and 3.2 generate wrong code for double on intel Reply-To: Bruce Allen X-SW-Source: 2002-10/txt/msg01256.txt.bz2 List-Id: The following reply was made to PR c/8395; it has been noted by GNATS. From: Bruce Allen 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 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); }