This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: IEEE128 binary float to decimal float conversion routines


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]