lua-users home
lua-l archive

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


> >   When a value of floating type is converted to integral type,
> >the fractional part is discarded.  If the value of the integral
> >part cannot be represented by the integral type, the behavior is
> >undefined. /23/
> >
> [...]
> >
> >Looks clear-cut to me ...
> >
> >
> >Philipp
> Oh well, then I looked at the wrong place. So the behavior is
> undefined, this means the P2020 is doing nothing that isn't allowed
> here, and maybe the code in the vanilla Lua source should be changed
> accordingly.
> 
> We were surprised that only we encountered the problem. I haven't
> found anything on the list about it.

Your system is correct, Lua is wrong. But we had never before met a
system that actually raises an error (so, there is nothing about
that on the list); we were a little over-confident with the
code ("always work").

Be aware that it is not easy to have a correct code that is also
efficient and portable (in particular, that works with both 32
and 64-bit integers). As we discussed recently on the list, integer
limits can be rounded when converted to floats.

(This is a "subliminial" reason for integers in Lua 5.3. Although this
problem is rare, we are aware that there are several details not very
clear in Lua about the conversion between floats and integers (e.g.,
how rounding is done), and that conversion is quite frequent at the C
API. In Lua 5.3 all that stuff is much more clear.)

-- Roberto