|
On 20/06/2023 17:14, Hugo Musso Gualandi wrote:
>
>> 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
>
> Currently we do try to support c89. Also, we found that using decimal
> when possible was more readable :)
>
> By the way, beware that "%a" doesn't always produce something that's a
> valid C or Lua literal. For example, it might return "inf" or "-nan".
Yep, that's why I mentioned C99 and strtod. In C99 strtod can convert
"inf" and "nan" to actual float infinities and NaNs.
IDK if Lua uses strtod internally to implement "tonumber", but if it
does and it is compiled as C99 it should (could?) support also "nan" and
"inf".