lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




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