Lines Matching +full:1 +full:l
29 static int math_abs (lua_State *L) { in math_abs() argument
30 if (lua_isinteger(L, 1)) { in math_abs()
31 lua_Integer n = lua_tointeger(L, 1); in math_abs()
33 lua_pushinteger(L, n); in math_abs()
36 lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1))); in math_abs()
37 return 1; in math_abs()
40 static int math_sin (lua_State *L) { in math_sin() argument
41 lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1))); in math_sin()
42 return 1; in math_sin()
45 static int math_cos (lua_State *L) { in math_cos() argument
46 lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1))); in math_cos()
47 return 1; in math_cos()
50 static int math_tan (lua_State *L) { in math_tan() argument
51 lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1))); in math_tan()
52 return 1; in math_tan()
55 static int math_asin (lua_State *L) { in math_asin() argument
56 lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1))); in math_asin()
57 return 1; in math_asin()
60 static int math_acos (lua_State *L) { in math_acos() argument
61 lua_pushnumber(L, l_mathop(acos)(luaL_checknumber(L, 1))); in math_acos()
62 return 1; in math_acos()
65 static int math_atan (lua_State *L) { in math_atan() argument
66 lua_Number y = luaL_checknumber(L, 1); in math_atan()
67 lua_Number x = luaL_optnumber(L, 2, 1); in math_atan()
68 lua_pushnumber(L, l_mathop(atan2)(y, x)); in math_atan()
69 return 1; in math_atan()
73 static int math_toint (lua_State *L) { in math_toint() argument
75 lua_Integer n = lua_tointegerx(L, 1, &valid); in math_toint()
77 lua_pushinteger(L, n); in math_toint()
79 luaL_checkany(L, 1); in math_toint()
80 luaL_pushfail(L); /* value is not convertible to integer */ in math_toint()
82 return 1; in math_toint()
86 static void pushnumint (lua_State *L, lua_Number d) { in pushnumint() argument
89 lua_pushinteger(L, n); /* result is integer */ in pushnumint()
91 lua_pushnumber(L, d); /* result is float */ in pushnumint()
95 static int math_floor (lua_State *L) { in math_floor() argument
96 if (lua_isinteger(L, 1)) in math_floor()
97 lua_settop(L, 1); /* integer is its own floor */ in math_floor()
99 lua_Number d = l_mathop(floor)(luaL_checknumber(L, 1)); in math_floor()
100 pushnumint(L, d); in math_floor()
102 return 1; in math_floor()
106 static int math_ceil (lua_State *L) { in math_ceil() argument
107 if (lua_isinteger(L, 1)) in math_ceil()
108 lua_settop(L, 1); /* integer is its own ceil */ in math_ceil()
110 lua_Number d = l_mathop(ceil)(luaL_checknumber(L, 1)); in math_ceil()
111 pushnumint(L, d); in math_ceil()
113 return 1; in math_ceil()
117 static int math_fmod (lua_State *L) { in math_fmod() argument
118 if (lua_isinteger(L, 1) && lua_isinteger(L, 2)) { in math_fmod()
119 lua_Integer d = lua_tointeger(L, 2); in math_fmod()
120 if ((lua_Unsigned)d + 1u <= 1u) { /* special cases: -1 or 0 */ in math_fmod()
121 luaL_argcheck(L, d != 0, 2, "zero"); in math_fmod()
122 lua_pushinteger(L, 0); /* avoid overflow with 0x80000... / -1 */ in math_fmod()
125 lua_pushinteger(L, lua_tointeger(L, 1) % d); in math_fmod()
128 lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1), in math_fmod()
129 luaL_checknumber(L, 2))); in math_fmod()
130 return 1; in math_fmod()
139 static int math_modf (lua_State *L) { in math_modf() argument
140 if (lua_isinteger(L ,1)) { in math_modf()
141 lua_settop(L, 1); /* number is its own integer part */ in math_modf()
142 lua_pushnumber(L, 0); /* no fractional part */ in math_modf()
145 lua_Number n = luaL_checknumber(L, 1); in math_modf()
148 pushnumint(L, ip); in math_modf()
150 lua_pushnumber(L, (n == ip) ? l_mathop(0.0) : (n - ip)); in math_modf()
156 static int math_sqrt (lua_State *L) { in math_sqrt() argument
157 lua_pushnumber(L, l_mathop(sqrt)(luaL_checknumber(L, 1))); in math_sqrt()
158 return 1; in math_sqrt()
162 static int math_ult (lua_State *L) { in math_ult() argument
163 lua_Integer a = luaL_checkinteger(L, 1); in math_ult()
164 lua_Integer b = luaL_checkinteger(L, 2); in math_ult()
165 lua_pushboolean(L, (lua_Unsigned)a < (lua_Unsigned)b); in math_ult()
166 return 1; in math_ult()
169 static int math_log (lua_State *L) { in math_log() argument
170 lua_Number x = luaL_checknumber(L, 1); in math_log()
172 if (lua_isnoneornil(L, 2)) in math_log()
175 lua_Number base = luaL_checknumber(L, 2); in math_log()
186 lua_pushnumber(L, res); in math_log()
187 return 1; in math_log()
190 static int math_exp (lua_State *L) { in math_exp() argument
191 lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1))); in math_exp()
192 return 1; in math_exp()
195 static int math_deg (lua_State *L) { in math_deg() argument
196 lua_pushnumber(L, luaL_checknumber(L, 1) * (l_mathop(180.0) / PI)); in math_deg()
197 return 1; in math_deg()
200 static int math_rad (lua_State *L) { in math_rad() argument
201 lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / l_mathop(180.0))); in math_rad()
202 return 1; in math_rad()
206 static int math_min (lua_State *L) { in math_min() argument
207 int n = lua_gettop(L); /* number of arguments */ in math_min()
208 int imin = 1; /* index of current minimum value */ in math_min()
210 luaL_argcheck(L, n >= 1, 1, "value expected"); in math_min()
212 if (lua_compare(L, i, imin, LUA_OPLT)) in math_min()
215 lua_pushvalue(L, imin); in math_min()
216 return 1; in math_min()
220 static int math_max (lua_State *L) { in math_max() argument
221 int n = lua_gettop(L); /* number of arguments */ in math_max()
222 int imax = 1; /* index of current maximum value */ in math_max()
224 luaL_argcheck(L, n >= 1, 1, "value expected"); in math_max()
226 if (lua_compare(L, imax, i, LUA_OPLT)) in math_max()
229 lua_pushvalue(L, imax); in math_max()
230 return 1; in math_max()
234 static int math_type (lua_State *L) { in math_type() argument
235 if (lua_type(L, 1) == LUA_TNUMBER) in math_type()
236 lua_pushstring(L, (lua_isinteger(L, 1)) ? "integer" : "float"); in math_type()
238 luaL_checkany(L, 1); in math_type()
239 luaL_pushfail(L); in math_type()
241 return 1; in math_type()
310 Rand64 state1 = state[1]; in nextrand()
315 state[1] = state1 ^ state2; in nextrand()
327 ** interval [0,1), getting the higher FIG bits from the
334 /* to scale to [0, 1), multiply by scaleFIG = 2^(-FIGS) */
335 #define scaleFIG (l_mathop(0.5) / ((Rand64)1 << (FIGS - 1)))
363 lu_int32 l; /* lower half */ member
382 static Rand64 packI (lu_int32 h, lu_int32 l) { in packI() argument
385 result.l = l; in packI()
392 return packI((i.h << n) | (trim32(i.l) >> (32 - n)), i.l << n); in Ishl()
398 i1->l ^= i2.l; in Ixor()
403 Rand64 result = packI(i1.h + i2.h, i1.l + i2.l); in Iadd()
404 if (trim32(result.l) < trim32(i1.l)) /* carry? */ in Iadd()
422 return packI((i.h << n) | (trim32(i.l) >> (32 - n)), in rotl()
423 (trim32(i.h) >> (32 - n)) | (i.l << n)); in rotl()
430 return packI((trim32(i.h) >> n) | (i.l << (32 - n)), in rotl1()
431 (i.h << (32 - n)) | (trim32(i.l) >> n)); in rotl1()
438 Rand64 res = times9(rotl(times5(state[1]), 7)); in nextrand()
439 Rand64 t = Ishl(state[1], 17); in nextrand()
441 Ixor(&state[3], state[1]); in nextrand()
442 Ixor(&state[1], state[2]); in nextrand()
454 /* an unsigned 1 with proper type */
455 #define UONE ((lu_int32)1)
461 #define scaleFIG (l_mathop(0.5) / (UONE << (FIGS - 1)))
494 lua_Number l = (lua_Number)(trim32(x.l) >> shiftLOW); in I2d() local
495 return (h + l) * scaleFIG; in I2d()
503 return (((lua_Unsigned)trim32(x.h) << 31) << 1) | (lua_Unsigned)trim32(x.l); in I2UInt()
508 return packI((lu_int32)((n >> 31) >> 1), (lu_int32)n); in Int2I()
534 if ((n & (n + 1)) == 0) /* is 'n + 1' a power of 2? */ in project()
538 /* compute the smallest (2^b - 1) not smaller than 'n' */ in project()
539 lim |= (lim >> 1); in project()
547 lua_assert((lim & (lim + 1)) == 0 /* 'lim + 1' is a power of 2, */ in project()
549 && (lim >> 1) < n); /* and it is the smallest one */ in project()
557 static int math_random (lua_State *L) { in math_random() argument
560 RanState *state = (RanState *)lua_touserdata(L, lua_upvalueindex(1)); in math_random()
562 switch (lua_gettop(L)) { /* check number of arguments */ in math_random()
564 lua_pushnumber(L, I2d(rv)); /* float between 0 and 1 */ in math_random()
565 return 1; in math_random()
567 case 1: { /* only upper limit */ in math_random()
568 low = 1; in math_random()
569 up = luaL_checkinteger(L, 1); in math_random()
571 lua_pushinteger(L, I2UInt(rv)); /* full random integer */ in math_random()
572 return 1; in math_random()
577 low = luaL_checkinteger(L, 1); in math_random()
578 up = luaL_checkinteger(L, 2); in math_random()
581 default: return luaL_error(L, "wrong number of arguments"); in math_random()
584 luaL_argcheck(L, low <= up, 1, "interval is empty"); in math_random()
587 lua_pushinteger(L, p + (lua_Unsigned)low); in math_random()
588 return 1; in math_random()
592 static void setseed (lua_State *L, Rand64 *state, in setseed() argument
596 state[1] = Int2I(0xff); /* avoid a zero state */ in setseed()
601 lua_pushinteger(L, n1); in setseed()
602 lua_pushinteger(L, n2); in setseed()
608 ** and the address of 'L' (in case the machine does address space layout
611 static void randseed (lua_State *L, RanState *state) { in randseed() argument
613 lua_Unsigned seed2 = (lua_Unsigned)(size_t)L; in randseed()
614 setseed(L, state->s, seed1, seed2); in randseed()
618 static int math_randomseed (lua_State *L) { in math_randomseed() argument
619 RanState *state = (RanState *)lua_touserdata(L, lua_upvalueindex(1)); in math_randomseed()
620 if (lua_isnone(L, 1)) { in math_randomseed()
621 randseed(L, state); in math_randomseed()
624 lua_Integer n1 = luaL_checkinteger(L, 1); in math_randomseed()
625 lua_Integer n2 = luaL_optinteger(L, 2, 0); in math_randomseed()
626 setseed(L, state->s, n1, n2); in math_randomseed()
642 static void setrandfunc (lua_State *L) { in setrandfunc() argument
643 RanState *state = (RanState *)lua_newuserdatauv(L, sizeof(RanState), 0); in setrandfunc()
644 randseed(L, state); /* initialize with a "random" seed */ in setrandfunc()
645 lua_pop(L, 2); /* remove pushed seeds */ in setrandfunc()
646 luaL_setfuncs(L, randfuncs, 1); in setrandfunc()
659 static int math_cosh (lua_State *L) { in math_cosh() argument
660 lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1))); in math_cosh()
661 return 1; in math_cosh()
664 static int math_sinh (lua_State *L) { in math_sinh() argument
665 lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1))); in math_sinh()
666 return 1; in math_sinh()
669 static int math_tanh (lua_State *L) { in math_tanh() argument
670 lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1))); in math_tanh()
671 return 1; in math_tanh()
674 static int math_pow (lua_State *L) { in math_pow() argument
675 lua_Number x = luaL_checknumber(L, 1); in math_pow()
676 lua_Number y = luaL_checknumber(L, 2); in math_pow()
677 lua_pushnumber(L, l_mathop(pow)(x, y)); in math_pow()
678 return 1; in math_pow()
681 static int math_frexp (lua_State *L) { in math_frexp() argument
683 lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e)); in math_frexp()
684 lua_pushinteger(L, e); in math_frexp()
688 static int math_ldexp (lua_State *L) { in math_ldexp() argument
689 lua_Number x = luaL_checknumber(L, 1); in math_ldexp()
690 int ep = (int)luaL_checkinteger(L, 2); in math_ldexp()
691 lua_pushnumber(L, l_mathop(ldexp)(x, ep)); in math_ldexp()
692 return 1; in math_ldexp()
695 static int math_log10 (lua_State *L) { in math_log10() argument
696 lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1))); in math_log10()
697 return 1; in math_log10()
751 LUAMOD_API int luaopen_math (lua_State *L) { in luaopen_math() argument
752 luaL_newlib(L, mathlib); in luaopen_math()
753 lua_pushnumber(L, PI); in luaopen_math()
754 lua_setfield(L, -2, "pi"); in luaopen_math()
755 lua_pushnumber(L, (lua_Number)HUGE_VAL); in luaopen_math()
756 lua_setfield(L, -2, "huge"); in luaopen_math()
757 lua_pushinteger(L, LUA_MAXINTEGER); in luaopen_math()
758 lua_setfield(L, -2, "maxinteger"); in luaopen_math()
759 lua_pushinteger(L, LUA_MININTEGER); in luaopen_math()
760 lua_setfield(L, -2, "mininteger"); in luaopen_math()
761 setrandfunc(L); in luaopen_math()
762 return 1; in luaopen_math()