From 00a40f4d6a94216f7e8d40d69ab5402292d5120d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 7 Aug 2002 17:54:38 -0300 Subject: [PATCH] ensure proper rounding --- lmathlib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lmathlib.c b/lmathlib.c index 81238131..435eeda5 100644 --- a/lmathlib.c +++ b/lmathlib.c @@ -1,5 +1,5 @@ /* -** $Id: lmathlib.c,v 1.47 2002/06/18 15:16:18 roberto Exp roberto $ +** $Id: lmathlib.c,v 1.48 2002/06/24 13:54:13 roberto Exp roberto $ ** Standard mathematical library ** See Copyright Notice in lua.h */ @@ -177,14 +177,14 @@ static int math_random (lua_State *L) { case 1: { /* only upper limit */ int u = luaL_check_int(L, 1); luaL_arg_check(L, 1<=u, 1, "interval is empty"); - lua_pushnumber(L, (int)(r*u)+1); /* integer between 1 and `u' */ + lua_pushnumber(L, (int)floor(r*u)+1); /* int between 1 and `u' */ break; } case 2: { /* lower and upper limits */ int l = luaL_check_int(L, 1); int u = luaL_check_int(L, 2); luaL_arg_check(L, l<=u, 2, "interval is empty"); - lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between `l' and `u' */ + lua_pushnumber(L, (int)floor(r*(u-l+1))+l); /* int between `l' and `u' */ break; } default: return luaL_error(L, "wrong number of arguments");