26 #define PI (l_mathop(3.141592653589793238462643383279502884)) 176 #if !defined(LUA_USE_C89) 210 for (i = 2; i <=
n; i++) {
224 for (i = 2; i <=
n; i++) {
252 #define FIGS l_floatatt(MANT_DIG) 265 #if !defined(LUA_RAND32) && !defined(Rand64) 269 #if (ULONG_MAX >> 31 >> 31) >= 3 272 #define Rand64 unsigned long 274 #elif !defined(LUA_USE_C89) && defined(LLONG_MAX) 277 #define Rand64 unsigned long long 279 #elif (LUA_MAXUNSIGNED >> 31 >> 31) >= 3 282 #define Rand64 lua_Unsigned 299 #define trim64(x) ((x) & 0xffffffffffffffffu) 304 return (x << n) | (trim64(x) >> (64 -
n));
310 Rand64 state2 = state[2] ^ state0;
311 Rand64 state3 = state[3] ^ state1;
313 state[0] = state0 ^ state3;
314 state[1] = state1 ^ state2;
315 state[2] = state2 ^ (state1 << 17);
316 state[3] =
rotl(state3, 45);
331 #define shift64_FIG (64 - FIGS) 334 #define scaleFIG (l_mathop(0.5) / ((Rand64)1 << (FIGS - 1))) 341 #define I2UInt(x) ((lua_Unsigned)trim64(x)) 344 #define Int2I(x) ((Rand64)(x)) 373 #define trim32(x) ((x) & 0xffffffffu) 422 (
trim32(i.
h) >> (32 - n)) | (i.
l << n));
430 (i.
h << (32 - n)) | (
trim32(i.
l) >> n));
439 Ixor(&state[2], state[0]);
440 Ixor(&state[3], state[1]);
441 Ixor(&state[1], state[2]);
442 Ixor(&state[0], state[3]);
444 state[3] =
rotl1(state[3], 45);
454 #define UONE ((lu_int32)1) 460 #define scaleFIG (l_mathop(0.5) / (UONE << (FIGS - 1))) 477 ((lua_Number)1.0 / (UONE << 30) / 8.0 / (UONE << (FIGS - 33))) 483 #define shiftLOW (64 - FIGS) 488 #define shiftHI ((lua_Number)(UONE << (FIGS - 33)) * 2.0) 533 if ((n & (n + 1)) == 0)
543 #if (LUA_MAXUNSIGNED >> 31) >= 3 549 while ((ran &= lim) > n)
580 default:
return luaL_error(L,
"wrong number of arguments");
594 state[0] =
Int2I(n1);
595 state[1] =
Int2I(0xff);
596 state[2] =
Int2I(n2);
598 for (i = 0; i < 16; i++)
656 #if defined(LUA_COMPAT_MATHLIB) 726 #if defined(LUA_COMPAT_MATHLIB) 732 {
"frexp", math_frexp},
733 {
"ldexp", math_ldexp},
734 {
"log10", math_log10},
738 {
"randomseed", NULL},
741 {
"maxinteger", NULL},
742 {
"mininteger", NULL},
static int math_random(lua_State *L)
static int math_randomseed(lua_State *L)
#define lua_isnoneornil(L, n)
LUA_API int lua_isinteger(lua_State *L, int idx)
static int math_ult(lua_State *L)
static lua_Number I2d(Rand64 x)
static int math_acos(lua_State *L)
static void pushnumint(lua_State *L, lua_Number d)
static void Ixor(Rand64 *i1, Rand64 i2)
LUA_API void * lua_touserdata(lua_State *L, int idx)
static const luaL_Reg mathlib[]
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
LUA_API int lua_compare(lua_State *L, int index1, int index2, int op)
LUA_API lua_Integer lua_tointegerx(lua_State *L, int idx, int *pisnum)
static int math_max(lua_State *L)
#define lua_tointeger(L, i)
static Rand64 packI(lu_int32 h, lu_int32 l)
static int math_asin(lua_State *L)
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
static Rand64 Ishl(Rand64 i, int n)
static int math_deg(lua_State *L)
static lua_Unsigned I2UInt(Rand64 x)
static void setrandfunc(lua_State *L)
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUA_API void lua_settop(lua_State *L, int idx)
static int math_modf(lua_State *L)
static int math_abs(lua_State *L)
#define lua_upvalueindex(i)
static Rand64 Iadd(Rand64 i1, Rand64 i2)
static int math_atan(lua_State *L)
#define lua_numbertointeger(n, p)
LUA_API void lua_pushboolean(lua_State *L, int b)
static int math_floor(lua_State *L)
static Rand64 rotl(Rand64 i, int n)
static void randseed(lua_State *L, RanState *state)
static int math_sin(lua_State *L)
static int math_type(lua_State *L)
static Rand64 Int2I(lua_Unsigned n)
static void setseed(lua_State *L, Rand64 *state, lua_Unsigned n1, lua_Unsigned n2)
static int math_ceil(lua_State *L)
static Rand64 times9(Rand64 i)
LUALIB_API void luaL_checkany(lua_State *L, int arg)
static int math_fmod(lua_State *L)
static int math_tan(lua_State *L)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int arg)
LUA_API void * lua_newuserdatauv(lua_State *L, size_t size, int nuvalue)
LUA_API int lua_type(lua_State *L, int idx)
static int math_toint(lua_State *L)
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int arg, lua_Integer def)
LUAMOD_API int luaopen_math(lua_State *L)
static const luaL_Reg randfuncs[]
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
#define luaL_newlib(L, l)
LUA_UNSIGNED lua_Unsigned
static int math_cos(lua_State *L)
#define luaL_argcheck(L, cond, arg, extramsg)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
static Rand64 nextrand(Rand64 *state)
LUALIB_API lua_Number luaL_checknumber(lua_State *L, int arg)
static lua_Unsigned project(lua_Unsigned ran, lua_Unsigned n, RanState *state)
LUALIB_API lua_Number luaL_optnumber(lua_State *L, int arg, lua_Number def)
static int math_rad(lua_State *L)
static Rand64 rotl1(Rand64 i, int n)
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
static Rand64 times5(Rand64 i)
static int math_sqrt(lua_State *L)
static int math_log(lua_State *L)
LUA_API int lua_gettop(lua_State *L)
static int math_min(lua_State *L)
static int math_exp(lua_State *L)