aboutsummaryrefslogtreecommitdiff
path: root/src/util
Commit message (Expand)AuthorAge
* v2d & aabbox3d<f32> & sky cleanupsnerzhul2016-02-11
* Add macos/freebsd missing endian.h include and add win endianness infoqiukeren2015-12-29
* Fix misc. MinGW and Valgrind warningskwolekr2015-11-08
* Don't compile pcgrandom on Windowsest312015-11-08
* Add server side ncurses terminalest312015-11-06
* Silence 'unused typedef' warning for STATIC_ASSERT()kwolekr2015-11-03
* Rename and move basicmacros.h to util/basic_macros.hest312015-11-02
* Move basic, non-numeric macros from util/numeric.h to basicmacros.hkwolekr2015-10-27
* Add BufReader and vector-based serialization methodskwolekr2015-10-15
* Rename macros with two leading underscoresShadowNinja2015-10-14
* Always use errorstream for DEBUG_EXCEPTION_HANDLERShadowNinja2015-10-14
* Fix some SRP issuesest312015-09-30
* Clean up threadingShadowNinja2015-08-23
* Fix indianred and indigo of color-stringRui2015-08-19
* Android: bypass broken wide_to_utf8 with wide_to_narrow (again)est312015-08-19
* Fix BufferedPacket race condition (fixes #2983)kwolekr2015-08-06
* Initialize random for verification key generation tooest312015-08-06
* src/util/numeric.{cpp,h}: Fix FacePositionCache data raceBřetislav Štec2015-08-02
* Improve accuracy and safety of float serializationkwolekr2015-08-01
* Clean up util/serialization.{cpp,h} and add unit testskwolekr2015-08-01
* Android: fix horrible libiconv buildest312015-07-29
* Add AreaStore data structureest312015-07-27
* Check output of mpz_set_str and fix leak on error conditionest312015-07-24
* Remove some old dead code. Fix some Clang warnings in SRP (ng->N... willLoic Blot2015-07-24
* Clarify docs for auth.cpp methodest312015-07-21
* Increase limit of serialized long stringskwolekr2015-07-14
* Add more robust error checking to deSerialize*String routineskwolekr2015-07-13
* Misc. minor fixeskwolekr2015-07-10
* Use UTF-8 instead of narrowest312015-07-08
* Add UpdateThread and use it for minimap and mesh threadsest312015-06-29
* Fix *BSD build with GNU iconvkwolekr2015-06-29
* Fix string conversion error messageest312015-06-23
* More correct wrap_rows implementationfigec2015-06-20
* Fix wrap_rows at inner byte of multibyte sequencefigec2015-06-18
* Make wrap_rows not wrap inside utf-8 multibyte sequencesest312015-06-17
* Fail iconv call gracefullyest312015-06-17
* Android: bypass broken wide_to_utf8 with wide_to_narrowest312015-06-14
* Add utf-8 conversion utilities and re-add intlGUIEditBoxest312015-06-13
* Split ObjDef/ObjDefManager out to objdef.cppkwolekr2015-05-18
* Make early protocol auth mechanism generic, and add SRPest312015-05-11
* Fix several MSVC issues numeric.hSmallJoker2015-05-01
* Fix fast leaves with texture_clean_transparent enabled.Aaron Suen2015-04-26
* Refactor around translatePasswordest312015-04-17
* Clean scaling pre-filter for formspec/HUD.Aaron Suen2015-04-01
* Fix set_bitskwolekr2015-03-31
* GenElementManager: Pass opaque handles to Lua and rename to ObjDefManagerkwolekr2015-03-31
* Clean up and tweak build systemShadowNinja2015-03-27
* Add support for the PCG32 PRNG algo (and associated script APIs)kwolekr2015-03-22
* MutexedQueue inherits must use std::deque instead of std::listLoic Blot2015-03-17
* For usages of assert() that are meant to persist in Release builds (when NDEB...Craig Robbins2015-03-07
pushnumber(L, asin(luaL_checknumber(L, 1))); return 1; } static int math_acos (lua_State *L) { lua_pushnumber(L, acos(luaL_checknumber(L, 1))); return 1; } static int math_atan (lua_State *L) { lua_pushnumber(L, atan(luaL_checknumber(L, 1))); return 1; } static int math_atan2 (lua_State *L) { lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); return 1; } static int math_ceil (lua_State *L) { lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); return 1; } static int math_floor (lua_State *L) { lua_pushnumber(L, floor(luaL_checknumber(L, 1))); return 1; } static int math_fmod (lua_State *L) { lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); return 1; } static int math_modf (lua_State *L) { double ip; double fp = modf(luaL_checknumber(L, 1), &ip); lua_pushnumber(L, ip); lua_pushnumber(L, fp); return 2; } static int math_sqrt (lua_State *L) { lua_pushnumber(L, sqrt(luaL_checknumber(L, 1))); return 1; } static int math_pow (lua_State *L) { lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); return 1; } static int math_log (lua_State *L) { lua_pushnumber(L, log(luaL_checknumber(L, 1))); return 1; } static int math_log10 (lua_State *L) { lua_pushnumber(L, log10(luaL_checknumber(L, 1))); return 1; } static int math_exp (lua_State *L) { lua_pushnumber(L, exp(luaL_checknumber(L, 1))); return 1; } static int math_deg (lua_State *L) { lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE); return 1; } static int math_rad (lua_State *L) { lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE); return 1; } static int math_frexp (lua_State *L) { int e; lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e)); lua_pushinteger(L, e); return 2; } static int math_ldexp (lua_State *L) { lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); return 1; } static int math_min (lua_State *L) { int n = lua_gettop(L); /* number of arguments */ lua_Number dmin = luaL_checknumber(L, 1); int i; for (i=2; i<=n; i++) { lua_Number d = luaL_checknumber(L, i); if (d < dmin) dmin = d; } lua_pushnumber(L, dmin); return 1; } static int math_max (lua_State *L) { int n = lua_gettop(L); /* number of arguments */ lua_Number dmax = luaL_checknumber(L, 1); int i; for (i=2; i<=n; i++) { lua_Number d = luaL_checknumber(L, i); if (d > dmax) dmax = d; } lua_pushnumber(L, dmax); return 1; } static int math_random (lua_State *L) { /* the `%' avoids the (rare) case of r==1, and is needed also because on some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */ lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX; switch (lua_gettop(L)) { /* check number of arguments */ case 0: { /* no arguments */ lua_pushnumber(L, r); /* Number between 0 and 1 */ break; } case 1: { /* only upper limit */ int u = luaL_checkint(L, 1); luaL_argcheck(L, 1<=u, 1, "interval is empty"); lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */ break; } case 2: { /* lower and upper limits */ int l = luaL_checkint(L, 1); int u = luaL_checkint(L, 2); luaL_argcheck(L, l<=u, 2, "interval is empty"); lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */ break; } default: return luaL_error(L, "wrong number of arguments"); } return 1; } static int math_randomseed (lua_State *L) { srand(luaL_checkint(L, 1)); return 0; } static const luaL_Reg mathlib[] = { {"abs", math_abs}, {"acos", math_acos}, {"asin", math_asin}, {"atan2", math_atan2}, {"atan", math_atan}, {"ceil", math_ceil}, {"cosh", math_cosh}, {"cos", math_cos}, {"deg", math_deg}, {"exp", math_exp}, {"floor", math_floor}, {"fmod", math_fmod}, {"frexp", math_frexp}, {"ldexp", math_ldexp}, {"log10", math_log10}, {"log", math_log}, {"max", math_max}, {"min", math_min}, {"modf", math_modf}, {"pow", math_pow}, {"rad", math_rad}, {"random", math_random}, {"randomseed", math_randomseed}, {"sinh", math_sinh}, {"sin", math_sin}, {"sqrt", math_sqrt}, {"tanh", math_tanh}, {"tan", math_tan}, {NULL, NULL} }; /* ** Open math library */ LUALIB_API int luaopen_math (lua_State *L) { luaL_register(L, LUA_MATHLIBNAME, mathlib); lua_pushnumber(L, PI); lua_setfield(L, -2, "pi"); lua_pushnumber(L, HUGE_VAL); lua_setfield(L, -2, "huge"); #if defined(LUA_COMPAT_MOD) lua_getfield(L, -1, "fmod"); lua_setfield(L, -2, "mod"); #endif return 1; }