This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: IEEE128 binary float to decimal float conversion routines
- From: Joseph Myers <joseph at codesourcery dot com>
- To: "Paul E. Murphy" <murphyp at linux dot vnet dot ibm dot com>
- Cc: Steve Munroe <sjmunroe at us dot ibm dot com>, "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>, Michael R Meissner <mrmeissn at us dot ibm dot com>, Tulio Magno Quites Machado Filho <tuliom at linux dot vnet dot ibm dot com>
- Date: Thu, 19 Nov 2015 18:14:16 +0000
- Subject: Re: IEEE128 binary float to decimal float conversion routines
- Authentication-results: sourceware.org; auth=none
- References: <564A16D5 dot 3020105 at linux dot vnet dot ibm dot com> <alpine dot DEB dot 2 dot 10 dot 1511161803500 dot 30498 at digraph dot polyomino dot org dot uk> <564A6A90 dot 40607 at linux dot vnet dot ibm dot com> <alpine dot DEB dot 2 dot 10 dot 1511162356020 dot 32387 at digraph dot polyomino dot org dot uk> <201511180131 dot tAI1Vs2L023118 at d03av01 dot boulder dot ibm dot com> <alpine dot DEB dot 2 dot 10 dot 1511180144150 dot 2302 at digraph dot polyomino dot org dot uk> <564E0D6E dot 7050204 at linux dot vnet dot ibm dot com>
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