lua-users home
lua-l archive

math package floating point exceptions

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


When Lua is used on Windows, floating point exceptions can crash the host application. I suggest adding some error checks, something like this:
static int math_asin (lua_State *L) {
 lua_Number arg = luaL_checknumber(L, 1);
 if (fabs(arg) > 1.0)
 	return luaL_error( L, "Illegal argument %f to math.asin", arg );
 lua_pushnumber(L, asin(arg));
 return 1;
}
Similar checks could also be added to acos, sqrt, pow, log, log10.
(I just joined the list, but first I searched the archive, and could not find anything about this.)
--
 James W. Walker, Innoventive Software LLC
 <http://www.frameforge3d.com/>

AltStyle によって変換されたページ (->オリジナル) /