[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LUA_COMPAT_FLOATSTRING
- From: Matthias Kluwe <mkluwe@...>
- Date: Wed, 1 Apr 2015 06:14:20 +0000 (UTC)
Hi!
Nagaev Boris <bnagaev <at> gmail.com> writes:
> On Tue, Mar 31, 2015 at 6:34 PM, Matthias Kluwe <mkluwe <at> gmail.com> wrote:
> > [...]
> >
> > print( os.setlocale 'german' )
> > print( 0.0, 0.1 )
> >
> > outputs
> >
> > German_Germany.1252
> > 0 0,1
> >
> > using Lua 5.2.4 and
> >
> > German_Germany.1252
> > 0.0 0,1
> >
> > with Lua 5.3.0.
> >
> > [...]
>
> Lua 5.3 manual says following [1]:
>
> The conversion of a float to a string now adds a .0 suffix to the result
> if it looks like an integer. (For instance, the float 2.0 will be printed
> as 2.0, not as 2.) You should always use an explicit format when you need
> a specific format for numbers. (Formally this is not an incompatibility,
> because Lua does not specify how numbers are formatted as strings, but
> some programs assumed a specific format.)
Ah, yes, I must admit that I did not take the manual too literally here
skipping through it when Lua 5.3 was released some time ago. I did not
expect that ".0" was meant to be read literally irrespectice of the locale
currently in effect.
> If I understand correctly, it was not documented in Lua < 5.3, how
> numbers are converted to strings. That is why this change is not
> considered to be an incompatibility. When undefined behavior becomes
> defined behavior, it is not called an incompatibility.
I agree that the behaviour is defined now, so that's not an incompatibility,
*technically*. But the behaviour is somewhat awkward, given the problem that
relatively simple code such as
table.concat( { 1, 0.0 }, ';' )
for generating CSV data stopped working for me.
Regards,
Matthias