From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58594 invoked by alias); 19 Nov 2015 18:14:25 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 58583 invoked by uid 89); 19 Nov 2015 18:14:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Date: Thu, 19 Nov 2015 18:14:00 -0000 From: Joseph Myers To: "Paul E. Murphy" CC: Steve Munroe , "libc-alpha@sourceware.org" , Michael R Meissner , Tulio Magno Quites Machado Filho Subject: Re: IEEE128 binary float to decimal float conversion routines In-Reply-To: <564E0D6E.7050204@linux.vnet.ibm.com> Message-ID: References: <564A16D5.3020105@linux.vnet.ibm.com> <564A6A90.40607@linux.vnet.ibm.com> <201511180131.tAI1Vs2L023118@d03av01.boulder.ibm.com> <564E0D6E.7050204@linux.vnet.ibm.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-SW-Source: 2015-11/txt/msg00473.txt.bz2 On Thu, 19 Nov 2015, Paul E. Murphy wrote: > On 11/17/2015 08:03 PM, Joseph Myers wrote: > > I read the paper Christoph helpfully pointed out. But heuristically, if > > you have a 128-bit input, you can expect there to be some input values for > > which, on converting to binary, the initial 24 bits are followed by (1 > > then about 127 0s, then other nonzero bits, or likewise with 0 followed by > > about 127 1s), just by random chance, and so you expect to need about 24 + > > 128 bits internal precision for the conversion so as to get a result that > > rounds correctly when truncated to float. > > Joseph, can you elaborate on this a bit further? I agree with your point that > you need more precision to properly convert, but I'm having trouble following > this bit. 128-bit input == IEEE decimal128? binary == IEEE binary32? Yes. If you are converting from a decimal format with A significant bits in the representation, to a binary format with B bits in the mantissa, you heuristically expect to need about A+B bits internal precision for correct rounding (in the worst case - if you're careful about error bounds and avoiding spurious exceptions, you can do an initial trial conversion with less precision and then test whether that was good enough to know the correctly rounded result). See Christoph's paper for a more detailed continued fraction analysis bounding the amount of precision needed (that paper deals with mixed-radix comparisons, but conversions are essentially the same issue). Much the same applies to conversions in the other direction (binary to decimal). -- Joseph S. Myers joseph@codesourcery.com