lua-users home
lua-l archive

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


> When I see ".0" in tostring or print("%s", my_num), it reminds me that
> I'm seeing a float value that happens to be an integral. As a Lua
> user, since I only have access to "numbers", I am getting this hint is
> a rare view into what is almost an implementation detail. I can see
> good reasons why "%f" as default was proposed over "%.f". However, I
> can't say that I think it improves things.
>
> There are many casual users that will run into subtle issues, because
> of this. Floating point considerations were always with us. However,
> they are going to be more *relevant*, now that there will be many more
> times when people will need to lop off the '.0' and some of their
> chosen methods will have unforeseen consequences. Adding the '.0' has
> none of the potential rounding hazards, by contrast.
>
> I will also add that if dropping number->string conversion is a
> consideration, my suggestion is to do it at the same time as integer
> divide / 64 bit int. My opinion is that it is better to do these
> changes in one go and since you've already made the ".0" change,
> people are more likely to be refactoring that code, anyway.

I agree with this. I think Lua 5.3 may be a good time to remove
all coercion from string to number and from number to string
from the language.

It means you should not be able to do this:

    answer = "6" * 7

or this:

    print(string.format("the answer is %s", 42))

The reason is that both of those are error-prone. And if you
really want to convert between those types, you can still use
tostring() and tonumber().

-- 
Pierre Chapuis