26#define PI (l_mathop(3.141592653589793238462643383279502884))
176#if !defined(LUA_USE_C89)
211 for (i = 2; i <= n; i++) {
225 for (i = 2; i <= n; i++) {
253#define FIGS l_floatatt(MANT_DIG)
266#if !defined(LUA_RAND32) && !defined(Rand64)
270#if (ULONG_MAX >> 31 >> 31) >= 3
273#define Rand64 unsigned long
275#elif !defined(LUA_USE_C89) && defined(LLONG_MAX)
278#define Rand64 unsigned long long
280#elif (LUA_MAXUNSIGNED >> 31 >> 31) >= 3
283#define Rand64 lua_Unsigned
300#define trim64(x) ((x) & 0xffffffffffffffffu)
305 return (x << n) | (trim64(x) >> (64 - n));
311 Rand64 state2 = state[2] ^ state0;
312 Rand64 state3 = state[3] ^ state1;
314 state[0] = state0 ^ state3;
315 state[1] = state1 ^ state2;
316 state[2] = state2 ^ (state1 << 17);
317 state[3] =
rotl(state3, 45);
332#define shift64_FIG (64 - FIGS)
335#define scaleFIG (l_mathop(0.5) / ((Rand64)1 << (FIGS - 1)))
342#define I2UInt(x) ((lua_Unsigned)trim64(x))
345#define Int2I(x) ((Rand64)(x))
374#define trim32(x) ((x) & 0xffffffffu)
423 (
trim32(i.
h) >> (32 - n)) | (i.
l << n));
431 (i.
h << (32 - n)) | (
trim32(i.
l) >> n));
440 Ixor(&state[2], state[0]);
441 Ixor(&state[3], state[1]);
442 Ixor(&state[1], state[2]);
443 Ixor(&state[0], state[3]);
445 state[3] =
rotl1(state[3], 45);
455#define UONE ((lu_int32)1)
461#define scaleFIG (l_mathop(0.5) / (UONE << (FIGS - 1)))
478 ((lua_Number)1.0 / (UONE << 30) / 8.0 / (UONE << (FIGS - 33)))
484#define shiftLOW (64 - FIGS)
489#define shiftHI ((lua_Number)(UONE << (FIGS - 33)) * 2.0)
534 if ((n & (n + 1)) == 0)
544#if (LUA_MAXUNSIGNED >> 31) >= 3
550 while ((ran &= lim) > n)
581 default:
return luaL_error(L,
"wrong number of arguments");
595 state[0] =
Int2I(n1);
596 state[1] =
Int2I(0xff);
597 state[2] =
Int2I(n2);
599 for (i = 0; i < 16; i++)
657#if defined(LUA_COMPAT_MATHLIB)
727#if defined(LUA_COMPAT_MATHLIB)
739 {
"randomseed",
NULL},
742 {
"maxinteger",
NULL},
743 {
"mininteger",
NULL},
LUA_API void lua_pushstring(lua_State *L, const char *s)
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
LUA_API void lua_pushboolean(lua_State *L, int b)
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUA_API int lua_type(lua_State *L, int idx)
LUA_API void * lua_touserdata(lua_State *L, int idx)
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API int lua_gettop(lua_State *L)
LUALIB_API lua_Number luaL_optnumber(lua_State *L, int narg, lua_Number def)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
LUALIB_API void luaL_checkany(lua_State *L, int narg)
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def)
LUALIB_API lua_Number luaL_checknumber(lua_State *L, int narg)
#define luaL_argcheck(L, cond, numarg, extramsg)
static int math_frexp(lua_State *L)
static int math_pow(lua_State *L)
static int math_tanh(lua_State *L)
static int math_log10(lua_State *L)
static int math_sinh(lua_State *L)
static int math_cosh(lua_State *L)
static int math_ldexp(lua_State *L)
#define lua_upvalueindex(i)
#define lua_isnoneornil(L, n)
LUA_API lua_Integer lua_tointegerx(lua_State *L, int idx, int *isnum)
LUA_API int lua_compare(lua_State *L, int index1, int index2, int op)
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
#define luaL_newlib(L, l)
#define lua_tointeger(L, i)
LUA_UNSIGNED lua_Unsigned
LUA_API int lua_isinteger(lua_State *L, int idx)
#define lua_numbertointeger(n, p)
LUA_API void * lua_newuserdatauv(lua_State *L, size_t size, int nuvalue)
static lua_Unsigned I2UInt(Rand64 x)
static int math_max(lua_State *L)
static int math_tan(lua_State *L)
static Rand64 rotl1(Rand64 i, int n)
static Rand64 Iadd(Rand64 i1, Rand64 i2)
static lua_Unsigned project(lua_Unsigned ran, lua_Unsigned n, RanState *state)
static lua_Number I2d(Rand64 x)
static int math_fmod(lua_State *L)
static Rand64 packI(lu_int32 h, lu_int32 l)
static Rand64 times5(Rand64 i)
static void setseed(lua_State *L, Rand64 *state, lua_Unsigned n1, lua_Unsigned n2)
static int math_randomseed(lua_State *L)
static int math_ult(lua_State *L)
static int math_rad(lua_State *L)
static int math_cos(lua_State *L)
static Rand64 Ishl(Rand64 i, int n)
static int math_atan(lua_State *L)
static int math_toint(lua_State *L)
LUAMOD_API int luaopen_math(lua_State *L)
static int math_exp(lua_State *L)
static int math_log(lua_State *L)
static Rand64 times9(Rand64 i)
static const luaL_Reg randfuncs[]
static int math_sqrt(lua_State *L)
static int math_abs(lua_State *L)
static int math_acos(lua_State *L)
static int math_floor(lua_State *L)
static int math_random(lua_State *L)
static void pushnumint(lua_State *L, lua_Number d)
static int math_asin(lua_State *L)
static void randseed(lua_State *L, RanState *state)
static int math_min(lua_State *L)
static Rand64 nextrand(Rand64 *state)
static void Ixor(Rand64 *i1, Rand64 i2)
static const luaL_Reg mathlib[]
static int math_deg(lua_State *L)
static int math_sin(lua_State *L)
static int math_modf(lua_State *L)
static int math_ceil(lua_State *L)
static void setrandfunc(lua_State *L)
static Rand64 Int2I(lua_Unsigned n)
static int math_type(lua_State *L)
static Rand64 rotl(Rand64 i, int n)
CURL_EXTERN CURLMcode curl_socket_t s