From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12587 invoked by alias); 27 Dec 2007 19:20:23 -0000 Received: (qmail 12578 invoked by uid 22791); 27 Dec 2007 19:20:22 -0000 X-Spam-Check-By: sourceware.org Received: from igw2.br.ibm.com (HELO igw2.br.ibm.com) (32.104.18.25) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 27 Dec 2007 19:20:15 +0000 Received: from mailhub3.br.ibm.com (mailhub3 [9.18.232.110]) by igw2.br.ibm.com (Postfix) with ESMTP id F000917F4B4 for ; Thu, 27 Dec 2007 17:15:03 -0200 (BRDT) Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.18.232.46]) by mailhub3.br.ibm.com (8.13.8/8.13.8/NCO v8.7) with ESMTP id lBRJK4Vm2686976 for ; Thu, 27 Dec 2007 17:20:11 -0200 Received: from d24av01.br.ibm.com (loopback [127.0.0.1]) by d24av01.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id lBRJK4hb028475 for ; Thu, 27 Dec 2007 17:20:04 -0200 Received: from [9.18.197.236] ([9.18.197.236]) by d24av01.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id lBRJK3eu028424 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 27 Dec 2007 17:20:03 -0200 Subject: Re: GDB/libiberty support for IBM long double From: Luis Machado Reply-To: luisgpm@linux.vnet.ibm.com To: gdb-patches@sourceware.org In-Reply-To: References: <200711090107.lA917ZGs027733@d12av02.megacenter.de.ibm.com> Content-Type: text/plain Date: Fri, 28 Dec 2007 01:20:00 -0000 Message-Id: <1198783208.7822.51.camel@gargoyle> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-12/txt/msg00424.txt.bz2 Hi folks, There appears to be a problem with the use of IBM long doubles. In specific situations the values are being shown in a wrong way. Follows an example of GDB HEAD: (gdb) ptype ld0 type = long double (gdb) p sizeof(ld0) $8 = 16 (gdb) set ld0=1.2 (gdb) p ld0 $9 = 1.39999980921857059001922607421875 (gdb) printf "Long Double 128: %.30Lg \n",ld0 Long Double 128: 1.39999980921857059001922607422 (gdb) printf "Long Double 128: %.30Lg \n",1.2 Long Double 128: 1.19999999999999995559107901499 (gdb) printf "Long Double 128: %.30Lg \n",(long double)1.2 Long Double 128: 1.39999980921857059001922607422 (gdb) The only correct value is when we don't have a value that is explicitly a long double, in which case we have 1.19999999999999995559107901499. I've tracked down the problem and it appears libiberty is doing wrong calculations when we have a long double. In particular, this piece of code from "floatformat_to_double:libiberty/floatformat.c:527": ===> code <==== if (exponent != 0) exponent -= mant_bits; ===> code <==== We really need to be able to decrement EXPONENT (even if it's zero) to get the right exponent value to call the ldexp(mant, exponent) function for the next iteration, thus leading to a correct long double value. Removing this condition fixes the problem, but i'm not sure this is 100% safe as this condition must have a purpose. Any ideas? Best regards, -- Luis Machado Software Engineer IBM Linux Technology Center