diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-12-27 15:33:22 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-12-27 15:33:22 -0200 |
commit | acdb0b741e31adebfa4f608f8bf23e65fa68d741 (patch) | |
tree | a4f3bb695c4b2ae03ef8e02d15953bc12de25a9d /lmathlib.c | |
parent | 5b08fcd5a1392a7440cae91e68f350a44b136806 (diff) | |
download | lua-acdb0b741e31adebfa4f608f8bf23e65fa68d741.tar.gz lua-acdb0b741e31adebfa4f608f8bf23e65fa68d741.tar.bz2 lua-acdb0b741e31adebfa4f608f8bf23e65fa68d741.zip |
comments.
Diffstat (limited to 'lmathlib.c')
-rw-r--r-- | lmathlib.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmathlib.c,v 1.21 1999/11/22 17:39:51 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.22 1999/12/14 18:31:20 roberto Exp roberto $ |
3 | ** Lua standard mathematical library | 3 | ** Standard mathematical library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
6 | 6 | ||
@@ -147,7 +147,7 @@ static void math_random (lua_State *L) { | |||
147 | some systems (SunOS!) "rand()" may return a value larger than RAND_MAX */ | 147 | some systems (SunOS!) "rand()" may return a value larger than RAND_MAX */ |
148 | double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX; | 148 | double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX; |
149 | if (lua_getparam(L, 1) == LUA_NOOBJECT) /* no arguments? */ | 149 | if (lua_getparam(L, 1) == LUA_NOOBJECT) /* no arguments? */ |
150 | lua_pushnumber(L, r); /* real between 0 & 1 */ | 150 | lua_pushnumber(L, r); /* real between 0 and 1 */ |
151 | else { | 151 | else { |
152 | int l, u; /* lower & upper limits */ | 152 | int l, u; /* lower & upper limits */ |
153 | if (lua_getparam(L, 2) == LUA_NOOBJECT) { /* only one argument? */ | 153 | if (lua_getparam(L, 2) == LUA_NOOBJECT) { /* only one argument? */ |
@@ -159,7 +159,7 @@ static void math_random (lua_State *L) { | |||
159 | u = luaL_check_int(L, 2); | 159 | u = luaL_check_int(L, 2); |
160 | } | 160 | } |
161 | luaL_arg_check(L, l<=u, 1, "interval is empty"); | 161 | luaL_arg_check(L, l<=u, 1, "interval is empty"); |
162 | lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between l & u */ | 162 | lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between `l' and `u' */ |
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||