public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "vincent at vinc17 dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/36578] New: cast to long double not taken into account when result stored to a double Date: Thu, 19 Jun 2008 14:20:00 -0000 [thread overview] Message-ID: <bug-36578-6373@http.gcc.gnu.org/bugzilla/> (raw) The following program shows that the casts to long double are not taken into account when the result to stored to a variable of type double. This bug occurs with gcc from 3.4 to 4.3.1, but didn't occur with gcc 3.3. The bug can be reproduced on a Linux/x86_64 machine (i.e. where the "double" type corresponds to the IEEE-754 double precision and the "long double" type corresponds to the traditional x86 extended precision) with the arguments: 4294967219 4294967429 (these arguments allow the double rounding effect to be visible). #include <stdio.h> #include <stdlib.h> int main (int argc, char **argv) { double a, b, c, d, e; long double al, bl, dl, el; if (argc != 3) exit (1); a = atof (argv[1]); b = atof (argv[2]); al = a; bl = b; c = a * b; d = (long double) a * (long double) b; e = al * bl; dl = (long double) a * (long double) b; el = al * bl; printf ("a = %.0f\n", a); printf ("b = %.0f\n", b); printf ("c = %.0f\n", c); printf ("d = %.0f\n", d); printf ("e = %.0f\n", e); printf ("dl = %.0Lf\n", dl); printf ("el = %.0Lf\n", el); return 0; } Incorrect result (with gcc 3.4 to gcc 4.3.1): a = 4294967219 b = 4294967429 c = 18446744314227707904 d = 18446744314227707904 e = 18446744314227712000 dl = 18446744314227709952 el = 18446744314227709952 Correct result (as given by gcc 3.3) is the same except: d = 18446744314227712000 Note: I compiled with the options -std=c99 -Wall -pedantic. -- Summary: cast to long double not taken into account when result stored to a double Product: gcc Version: 4.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: vincent at vinc17 dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36578
next reply other threads:[~2008-06-19 14:20 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-06-19 14:20 vincent at vinc17 dot org [this message] 2008-06-19 14:37 ` [Bug middle-end/36578] " vincent at vinc17 dot org 2008-06-21 16:42 ` rguenth at gcc dot gnu dot org 2008-06-21 16:59 ` joseph at codesourcery dot com 2008-10-29 17:06 ` jsm28 at gcc dot gnu dot org 2008-10-29 17:12 ` jsm28 at gcc dot gnu dot org 2009-02-25 22:09 ` janis at gcc dot gnu dot org
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=bug-36578-6373@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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).