lua-users home
lua-l archive

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

> Date: Wed, 17 Jul 2013 10:52:57 -0300
> From: Roberto Ierusalimschy <>
> Subject: Re: Manual unclear on lua_tointegerx and lua_tounsignedx
> For Lua 5.3, the documentation says this:
>   Converts the Lua value at the given index to the signed integral type
>   lua_Integer. The Lua value must be an integer, or a number or string
>   convertible to an integer (see '3.4.2); otherwise, lua_tointegerx
>   returns 0.
> Again, if the value is not what it should be, the operation does not
> succeed. Should we explain that? (The details of what is "convertible
> to an integer" are explained in 3.4.2, as documented.)

OK, I see - if the value is a float that after 'floor' is out of range, the
function returns 0 and 'isnum' false. Maybe the parameter name should be
changed to 'isok' or 'isvalid'. Was consideration given to just saturating
the result? (OK, this has pros and cons for automatic coercion/conversion,
but for lua_tointegerx it could saturate the return value, but still set
'iswhatever' false.)

> > Also, in lua_tounsignedx ( in the 5.0.3 draft ):
> >
> > "If the number is not an integer, it is rounded towards minus
> infinite
> > (floor). If the result is outside the range of representable values,
> it is
> > normalized to the module of its division by one more than the maximum
> > representable value."
> >
> > Sorry if my math is letting me down, but does this specify what
> happens if
> > the value is negative?

So given the (sensible) specification for lua_tointegerx, why do something
different for lua_tounsignedx? Why not simply fail all out-of-range values
(including all negative values)? And this phrasing still does not quite nail
down whether, if the result has to be normalised, 'isnum' will be true or

- John