lua-users home
lua-l archive

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


> > 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)
> (Soni)

> About the quiz, in version 5.2, I believe that all values are considered
> equal to 2.
> (Charles)

> IIRC, in practice, lua always rounds down. so:
> aa
> 2
> aa
> 2
(Daurnimator)

"Undefined" is correct according to the manual, but (unlike 5.3) the
implementation thinks otherwise. And none of these answers match what my
machine (an ordinary Pentium/Linux) does.  Anyone else want to try an
answer?

-- Roberto


-- Roberto