mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-11-10 23:31:50 +00:00
error conditions for Lua fixed point math
This commit is contained in:
parent
be7b866e4f
commit
18d5d64a4d
1 changed files with 9 additions and 2 deletions
|
@ -100,7 +100,11 @@ static int lib_fixedint(lua_State *L)
|
|||
|
||||
static int lib_fixeddiv(lua_State *L)
|
||||
{
|
||||
lua_pushfixed(L, FixedDiv(luaL_checkfixed(L, 1), luaL_checkfixed(L, 2)));
|
||||
fixed_t i = luaL_checkfixed(L, 1);
|
||||
fixed_t j = luaL_checkfixed(L, 2);
|
||||
if (j == 0)
|
||||
return luaL_error(L, "divide by zero");
|
||||
lua_pushfixed(L, FixedDiv(i, j));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -112,7 +116,10 @@ static int lib_fixedrem(lua_State *L)
|
|||
|
||||
static int lib_fixedsqrt(lua_State *L)
|
||||
{
|
||||
lua_pushfixed(L, FixedSqrt(luaL_checkfixed(L, 1)));
|
||||
fixed_t i = luaL_checkfixed(L, 1);
|
||||
if (i < 0)
|
||||
return luaL_error(L, "can't take the square root of a negative number");
|
||||
lua_pushfixed(L, FixedSqrt(i));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue