From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16061 invoked by alias); 16 Aug 2012 16:20:56 -0000 Received: (qmail 16025 invoked by uid 22791); 16 Aug 2012 16:20:54 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-out.m-online.net (HELO mail-out.m-online.net) (212.18.0.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Aug 2012 16:20:25 +0000 Received: from frontend1.mail.m-online.net (frontend1.mail.intern.m-online.net [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 3WyXnz6nMVz3hhY1; Thu, 16 Aug 2012 18:20:23 +0200 (CEST) X-Auth-Info: tmj2bC2ugJaPUin6S6tTRQE2z1eHWR/m6frwRDgZaKc= Received: from igel.home (ppp-93-104-138-157.dynamic.mnet-online.de [93.104.138.157]) by mail.mnet-online.de (Postfix) with ESMTPA id 3WyXnz3pRYzbbgL; Thu, 16 Aug 2012 18:20:23 +0200 (CEST) Received: by igel.home (Postfix, from userid 501) id F0740CA2A3; Thu, 16 Aug 2012 18:20:22 +0200 (CEST) From: Andreas Schwab To: Ian Lance Taylor Cc: gcc-patches@gcc.gnu.org, gdb-patches@sourceware.org Subject: Re: RFA: Support infinity, NaN, and denormalized numbers in floatformat.c References: <20031203181245.3896.qmail@gossamer.airs.com> X-Yow: Remember, in 2039, MOUSSE & PASTA will be available ONLY by prescription!! Date: Thu, 16 Aug 2012 16:20:00 -0000 In-Reply-To: <20031203181245.3896.qmail@gossamer.airs.com> (Ian Lance Taylor's message of "3 Dec 2003 13:12:45 -0500") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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: 2012-08/txt/msg00456.txt.bz2 Ian Lance Taylor writes: > @@ -306,8 +359,18 @@ floatformat_to_double (fmt, from, to) > mant = get_field (ufrom, fmt->byteorder, fmt->totalsize, > mant_off, mant_bits); > > - dto += ldexp ((double)mant, exponent - mant_bits); > - exponent -= mant_bits; > + /* Handle denormalized numbers. FIXME: What should we do for > + non-IEEE formats? */ > + if (exponent == 0 && mant != 0) > + dto += ldexp ((double)mant, > + (- fmt->exp_bias > + - mant_bits > + - (mant_off - fmt->man_start) > + + 1)); > + else > + dto += ldexp ((double)mant, exponent - mant_bits); > + if (exponent != 0) > + exponent -= mant_bits; That mishandles numbers between 1 and 2 (ie. where the unbiased exponent is zero) with floating-point formats with more than 32 mantissa bits. Also, the handling of denormal numbers can be simplified by just setting exponent appropriately. Andreas. * floatformat.c (floatformat_to_double): Correctly handle numbers between 1 and 2. Simplify handling of denormal number. (main): Test with 1.1. --- libiberty/floatformat.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/libiberty/floatformat.c b/libiberty/floatformat.c index 1116c63..c58ab01 100644 --- a/libiberty/floatformat.c +++ b/libiberty/floatformat.c @@ -1,5 +1,5 @@ /* IEEE floating point support routines, for GDB, the GNU Debugger. - Copyright 1991, 1994, 1999, 2000, 2003, 2005, 2006, 2010 + Copyright 1991, 1994, 1999, 2000, 2003, 2005, 2006, 2010, 2012 Free Software Foundation, Inc. This file is part of GDB. @@ -463,7 +463,6 @@ floatformat_to_double (const struct floatformat *fmt, unsigned long mant; unsigned int mant_bits, mant_off; int mant_bits_left; - int special_exponent; /* It's a NaN, denorm or zero */ /* Split values are not handled specially, since the top half has the correctly rounded double value (in the only supported case of @@ -503,20 +502,20 @@ floatformat_to_double (const struct floatformat *fmt, mant_off = fmt->man_start; dto = 0.0; - special_exponent = exponent == 0 || (unsigned long) exponent == fmt->exp_nan; - - /* Don't bias zero's, denorms or NaNs. */ - if (!special_exponent) - exponent -= fmt->exp_bias; - /* Build the result algebraically. Might go infinite, underflow, etc; who cares. */ - /* If this format uses a hidden bit, explicitly add it in now. Otherwise, - increment the exponent by one to account for the integer bit. */ - - if (!special_exponent) + /* For denorms use minimum exponent. */ + if (exponent == 0) + exponent = 1 - fmt->exp_bias; + else { + exponent -= fmt->exp_bias; + + /* If this format uses a hidden bit, explicitly add it in now. + Otherwise, increment the exponent by one to account for the + integer bit. */ + if (fmt->intbit == floatformat_intbit_no) dto = ldexp (1.0, exponent); else @@ -530,18 +529,8 @@ floatformat_to_double (const struct floatformat *fmt, mant = get_field (ufrom, fmt->byteorder, fmt->totalsize, mant_off, mant_bits); - /* Handle denormalized numbers. FIXME: What should we do for - non-IEEE formats? */ - if (special_exponent && exponent == 0 && mant != 0) - dto += ldexp ((double)mant, - (- fmt->exp_bias - - mant_bits - - (mant_off - fmt->man_start) - + 1)); - else - dto += ldexp ((double)mant, exponent - mant_bits); - if (exponent != 0) - exponent -= mant_bits; + dto += ldexp ((double) mant, exponent - mant_bits); + exponent -= mant_bits; mant_off += mant_bits; mant_bits_left -= mant_bits; } @@ -756,6 +745,7 @@ main (void) { ieee_test (0.0); ieee_test (0.5); + ieee_test (1.1); ieee_test (256.0); ieee_test (0.12345); ieee_test (234235.78907234); -- 1.7.11.5 -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."