[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: LUA_COMPAT_FLOATSTRING
- From: Matthias Kluwe <mkluwe@...>
- Date: Tue, 31 Mar 2015 20:34:53 +0200
Hi!
When converting a number object to a string, luaO_tostring gets called,
which adds a "float mark" to floating point numbers that come out of
sprint looking like an int, to the effect that "0" becomes "0.0".
This can be turned off by defining LUA_COMPAT_FLOATSTRING.
luaconf.h says: "This macro is not on by default even in compatibility
mode, because this is not really an incompatibility."
I slightly disagree, as it introduces an incompatibility when using
different locales for output.
This example (expecting decimal comma representation)
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.
I had to learn that the hard way yesterday when my output containing
(floating point) zeros got severely borked. I *know* that using
unformatted output after switching to 5.3 means asking for some trouble,
but adding hard-coded '.0' to the number does not look like a sensible
default to me.
Regards,
Matthias