lua-users home
lua-l archive

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



On 17/12/14 03:34 PM, Roberto Ierusalimschy wrote:
I have checked 100k Lua source and see a few errors (sometimes crash).

[...]

I don't know what is the best solution.
Actually I try to replace all '/' with '//' where I want integer division.
That certainly would help, but an essential point is to understand how
you *want* to round these values.

As this point has come up several times, I have a quick quiz for this
list. Without running the code, what are the results of the following
expressions in Lua 5.2?

   string.rep("a", 2.7)
   string.format("%d", 2.7)
   string.rep("a", 2.3)
   string.format("%d", 2.3)
Undefined, Undefined, Undefined, Undefined, or with GCC, "aaa", "3", "aa", "2" (pretty sure GCC rounds properly? I may be wrong)
-- Roberto


--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.