[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: serialization of lua numbers
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Sun, 25 Mar 2012 13:01:35 -0300
> Stupid question maybe, but is there a way (without having to write a C
> module) to serialize Lua numbers without loss of precision? Eg. I
> tried printing a 5/6 with tostring, string.format with all formats
> immaginable etc. but couldn't get back a clean 5/6.
If you are using double-precision Lua numbers (the default), print them
with %0.17g. This allows you to read them back without loss. However,
as explained in a previous answer, you'll still won't be able to represent
5/6 exactly. On the other hand, 5/6 does seem to be exact in the sense
that this code prints true:
a=5/6
b=6*a
print(b==5)
This is not a contradiction...