diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-05-26 14:10:22 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-05-26 14:10:22 -0300 |
| commit | c98f195eb930422be2829f78696fb4bf79b93677 (patch) | |
| tree | 119b0eca4b1b1435f6a73cecb50e368455081c14 /lvm.c | |
| parent | 4d696c45b9710e4b3d2eb65a0ebef79766937a4a (diff) | |
| download | lua-c98f195eb930422be2829f78696fb4bf79b93677.tar.gz lua-c98f195eb930422be2829f78696fb4bf79b93677.tar.bz2 lua-c98f195eb930422be2829f78696fb4bf79b93677.zip | |
function 'luaV_numtointeger' changed to a global macro
'lua_numtointeger' (tricky, small, and useful in several places)
Diffstat (limited to 'lvm.c')
| -rw-r--r-- | lvm.c | 20 |
1 files changed, 2 insertions, 18 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.212 2014/05/20 14:12:59 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.213 2014/05/23 18:32:21 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -80,22 +80,6 @@ int luaV_tonumber_ (const TValue *obj, lua_Number *n) { | |||
| 80 | 80 | ||
| 81 | 81 | ||
| 82 | /* | 82 | /* |
| 83 | ** Check whether a float number is within the range of a lua_Integer. | ||
| 84 | ** (The comparisons are tricky because of rounding, which can or | ||
| 85 | ** not occur depending on the relative sizes of floats and integers.) | ||
| 86 | ** This function should be called only when 'n' has an integral value. | ||
| 87 | */ | ||
| 88 | int luaV_numtointeger (lua_Number n, lua_Integer *p) { | ||
| 89 | if (cast_num(LUA_MININTEGER) <= n && n < (LUA_MAXINTEGER + cast_num(1))) { | ||
| 90 | *p = cast(lua_Integer, n); | ||
| 91 | lua_assert(cast_num(*p) == n); | ||
| 92 | return 1; | ||
| 93 | } | ||
| 94 | return 0; /* number is outside integer limits */ | ||
| 95 | } | ||
| 96 | |||
| 97 | |||
| 98 | /* | ||
| 99 | ** try to convert a value to an integer, rounding up if 'up' is true | 83 | ** try to convert a value to an integer, rounding up if 'up' is true |
| 100 | */ | 84 | */ |
| 101 | static int tointeger_aux (const TValue *obj, lua_Integer *p, int up) { | 85 | static int tointeger_aux (const TValue *obj, lua_Integer *p, int up) { |
| @@ -104,7 +88,7 @@ static int tointeger_aux (const TValue *obj, lua_Integer *p, int up) { | |||
| 104 | if (ttisfloat(obj)) { | 88 | if (ttisfloat(obj)) { |
| 105 | lua_Number n = fltvalue(obj); | 89 | lua_Number n = fltvalue(obj); |
| 106 | n = (up ? -l_floor(-n) : l_floor(n)); | 90 | n = (up ? -l_floor(-n) : l_floor(n)); |
| 107 | return luaV_numtointeger(n, p); | 91 | return lua_numtointeger(n, p); |
| 108 | } | 92 | } |
| 109 | else if (ttisinteger(obj)) { | 93 | else if (ttisinteger(obj)) { |
| 110 | *p = ivalue(obj); | 94 | *p = ivalue(obj); |
