lua-users home
lua-l archive

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


On Jul 3, 2014, at 6:09 AM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:

>> The problem, according to the IEEE floating point entries on Wikipedia, is that there are not enough digits specified.
> 
> This is on purpose so that numbers appear right for the casual user:
> 
>> a=0.1
>> =a
>     0.1
>> =string.format("%.17g",a)
>     0.10000000000000001
> 
> We don't want needless noise when using print (and other automatic
> conversions via tostring). If you need round-trip strings, then use
> string.format.

Ah, well that is a great reason to not specify larger format specifiers, I didn't realise 0.1 would turn into 0.10000000000000001 with a larger specifier. When I was reading about specifier digits I did not find any information on this side-effect.

Thank you for the feedback on this matter Luiz, it is appreciated! I think by default I will simply pass through the original number format, and if someone wants to convert numbers I can use my own format specifiers instead of the default ones.

~pmd