diff options
| -rw-r--r-- | lmathlib.c | 16 |
1 files changed, 8 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.71 2009/02/18 13:06:05 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.72 2009/02/18 13:17:10 roberto Exp roberto $ |
| 3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -201,16 +201,16 @@ static int math_random (lua_State *L) { | |||
| 201 | break; | 201 | break; |
| 202 | } | 202 | } |
| 203 | case 1: { /* only upper limit */ | 203 | case 1: { /* only upper limit */ |
| 204 | int u = luaL_checkint(L, 1); | 204 | lua_Number u = luaL_checknumber(L, 1); |
| 205 | luaL_argcheck(L, 1<=u, 1, "interval is empty"); | 205 | luaL_argcheck(L, 1.0 <= u, 1, "interval is empty"); |
| 206 | lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */ | 206 | lua_pushnumber(L, floor(r*u) + 1.0); /* int between 1 and `u' */ |
| 207 | break; | 207 | break; |
| 208 | } | 208 | } |
| 209 | case 2: { /* lower and upper limits */ | 209 | case 2: { /* lower and upper limits */ |
| 210 | int l = luaL_checkint(L, 1); | 210 | lua_Number l = luaL_checknumber(L, 1); |
| 211 | int u = luaL_checkint(L, 2); | 211 | lua_Number u = luaL_checknumber(L, 2); |
| 212 | luaL_argcheck(L, l<=u, 2, "interval is empty"); | 212 | luaL_argcheck(L, l <= u, 2, "interval is empty"); |
| 213 | lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */ | 213 | lua_pushnumber(L, floor(r*(u-l+1)) + l); /* int between `l' and `u' */ |
| 214 | break; | 214 | break; |
| 215 | } | 215 | } |
| 216 | default: return luaL_error(L, "wrong number of arguments"); | 216 | default: return luaL_error(L, "wrong number of arguments"); |
