[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Formatting numbers without precision loss
- From: Andrew Gierth <andrew@...>
- Date: Tue, 20 Jun 2023 22:47:47 +0100
>>>>> "Hugo" == Hugo Musso Gualandi <hgualandi@inf.puc-rio.br> writes:
Hugo> In Pallene we try from "%.6g" to "%.17g" and pick the smallest
Hugo> one that round-trips to the original number.
This sounds like it would be useful to adopt the Ryu floating-point
output code (which renders a double as the shortest-exact
representation, which might not be the same as any %.*g output value).
As a bonus, the Ryu code is exceptionally fast, much faster than any
sprintf call in fact. The main downside is that it needs about 10 kbytes
of lookup tables for 64-bit floats.
(By "shortest-exact" representation, I mean the number with the fewest
decimal digits that falls within the interval of values which is closer
to the exact binary value than to any other representable binary value.)
--
Andrew.