[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Formatting numbers without precision loss
- From: Lorenzo Donati <lorenzodonatibz@...>
- Date: Tue, 20 Jun 2023 16:53:06 +0200
On 20/06/2023 16:14, Hugo Musso Gualandi wrote:
In Pallene we try from "%.6g" to "%.17g" and pick the smallest one that
round-trips to the original number. (We can't use %a because our output
is C, not Lua).
Are you bound to C89? C99 has %a:
https://en.cppreference.com/w/c/io/fprintf
Note in the table down that page where %a is mentioned:
"The default precision is sufficient for exact representation of the value."
Moreover "strtod" support that syntax (BTW, it also supports infinities
and NaNs):
https://en.cppreference.com/w/c/string/byte/strtof
so you can have perfect round-trip conversion.
-- Lorenzo