diff --git a/src/lua_mathlib.c b/src/lua_mathlib.c index 8ca2e17af8283bfc9fcdd2eab28a6d8131bfa6b6..f4b5ca5fe943915d680c8f3a57f320e48848fb26 100644 --- a/src/lua_mathlib.c +++ b/src/lua_mathlib.c @@ -77,7 +77,9 @@ static int lib_finecosine(lua_State *L) static int lib_finetangent(lua_State *L) { - lua_pushfixed(L, FINETANGENT((luaL_checkangle(L, 1)>>ANGLETOFINESHIFT) & FINEMASK)); + // HACK: add ANGLE_90 to make tan() in Lua start at 0 like it should + // use & 4095 instead of & FINEMASK (8191), so it doesn't go out of the array's bounds + lua_pushfixed(L, FINETANGENT(((luaL_checkangle(L, 1)+ANGLE_90)>>ANGLETOFINESHIFT) & 4095)); return 1; }