lua-users home
lua-l archive

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


> > If a program
> > specifices 3.2 as a character index in a string, is it useful to
> > silently truncate that to 3? Or maybe it would be better to throw an
> > error in that case?  In the rare cases that the programmer really wants
> > to truncate, that probably should be done explicitly.
> 
> In inexact floating point we say not to compare for equality with 3.0;
> instead check for a result within epsilon of 3.0. But with truncation,
> (3.0-epsilon) is 2, right? Does that affect any real programs?

No. Truncation inside Lua will (would?) only take place with the new
integer-only operators ('//' and bitwise operators). So, no matter
how it is done, it would not affect real existing programs.

The other place where truncation (already) occurs is "outside" Lua,
in the API, when the C code uses things like lua_checkinteger. This
is the only place where the change would affect compatibility:
string.sub("abc", 2.3) currently behaves in a non-specified way
(although most certainly it is equivalent to string.sub("abc", 2)
and we are afraid some programmers assume this behavior); current
5.3w specifies that 2.3 should be truncated to 2, while with this new
proposal Lua would raise an error.

-- Roberto