lua-users home
lua-l archive

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


2013/6/5 liam mail <liam.list@googlemail.com>:

> Sorry could you maybe explain what problem you have with the current
> wording, not forgetting to separate the language specification (manual) from
> one implementation of the specification (Rio Lua 5.2).

In numerical analysis courses, one is taught that truncation means discarding
fractional digits.

trunc(3.14) --> 3
trunc(-3.14) --> -3

Whereas rounding means taking the nearest integer.

round(3.14) --> 3
round(3.86) --> 4

"Nearest" might be ambiguous.

"Round towards zero": rounddown(3.5)=3
"Round away from zero": roundup(3.5)=4

There's also round-to-even and round-to-odd for breaking ties.

Rounding has many variations and in the absence of specific information
"in some unspecified way" is the best one can say. The error is never
more than 0.5,though.

So if the intention of the Manual is merely to say that a Number will be
rounded or truncated, nobody can say which, it should say "converted
to an integer in  some unspecified way". If the intention is to say the integer
will be the closest but to leave open the ambiguous case, it should say
"rounded in  some unspecified way." But "truncated" is a precise term, it
is never "in some unspecified way".