lua-users home
lua-l archive

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


On Thu, Jun 09, 2011 at 11:15:00AM +0200, David Kastrup wrote:
> > Maybe _because_ it's hard to distinguish them otherwise? :-)
> > Anyway, this is a question to ask of the people who define
> > the behaviour of C formatting.
> 
> C has a separate integer type.

The design decision to be made by the Lua designers is basically
what to put in luaconf.h.  At present, it says:

#define LUA_NUMBER_FMT          "%.14g"
#define lua_number2str(s,n)     sprintf((s), LUA_NUMBER_FMT, (n))

Are you (who obviously are arguing for the sheer joy of it) or any
of the people who are genuinely perplexed by -0, seriously suggesting
that Luiz should replace these two clear, effective lines by some
tortuous coding involving a test on n?  Plus the inevitable need
for explaining why Lua behaves differently from C in this case?

All that, when all it takes for the Lua user who wants to print 0
instead of -0, to put at the top of each Lua program he writes

debug.setmetatable(0, {__tostring = 
    function(n) local s=string.format("%.14g",n) 
    if s=='-0' then s='0' end return s 
    end})

Dirk