[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: math.random returning out of range values
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Wed, 7 Nov 2012 07:07:14 -0200
> The unfortunate effect of:
>
> lua_pushnumber(L, floor(r*(u-l+1))+l);
No, it's the unfortunate effect of
int l = luaL_checkint(L, 1);
int u = luaL_checkint(L, 2);
In 5.2 it's
lua_Number l = luaL_checknumber(L, 1);
lua_Number u = luaL_checknumber(L, 2);
and so we have full precision in floor(r*(u-l+1))+l.