[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: 5.3.0-work3 and lossless integer conversion
- From: Tim Hill <drtimhill@...>
- Date: Tue, 24 Jun 2014 10:08:50 -0700
On Jun 24, 2014, at 8:20 AM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>
> To be honest, we never thought much about that. Integers first entered
> Lua through the C API (lua_pushinteger, lua_tointeger), and we followed
> C in truncating floats when doing the conversion. (It was also cheaper,
> which was important because such conversions were quite common.) But
> the question is quite pertinent: is this useful at all? 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.
>
If Lua starts to do that, then the integer “sub-type” is starting to look more and more like a first-class type to me. I think it also becomes important to distinguish between “integral value” and “integer sub-type”, since these are subtly different (integers yield integer results for arithmetic, integral values, regardless of float/integer representation, can be used for string indexing etc).
—Tim