From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1225 invoked by alias); 18 Oct 2007 15:24:27 -0000 Received: (qmail 1195 invoked by uid 48); 18 Oct 2007 15:24:18 -0000 Date: Thu, 18 Oct 2007 15:24:00 -0000 Message-ID: <20071018152418.1194.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug middle-end/21718] real.c rounding not perfect In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "neil at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-10/txt/msg01627.txt.bz2 ------- Comment #6 from neil at gcc dot gnu dot org 2007-10-18 15:24 ------- (In reply to comment #5) > I believe more than 160 bits are required to get even single-precision numbers > right with DECIMAL_DIG digits precision and an exponent. I'm going to try and > prove this by finding an example. It could be hard as I believe 160 is only > just below the required number. Here's an example to prove this assertion. When compiled with GCC 4.1.2 or 4.1.3 with -std=c99, assuming a correctly-rounding libc (e.g. NetBSD's; glibc also seems to get this correct) you get the following output: 0x1.8p-147 0x1.4p-147 8.40779078594890243e-45 So not only is it rounded incorrectly, but the number it is rounded to, when converted back to decimal, does not even match the input number in the first digit. #include #include int main (void) { float f1 = 7.7071415537864938e-45; float f2 = strtof ("7.7071415537864938e-45", NULL); printf( "%a %a %0.18g\n", f1, f2, f1); return 0; } -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21718