MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaK_numberK

Function luaK_numberK

third-party/lua-5.4.6/src/lcode.c:603–620  ·  view source on GitHub ↗

** Add a float to list of constants and return its index. Floats ** with integral values need a different key, to avoid collision ** with actual integers. To that, we add to the number its smaller ** power-of-two fraction that is still significant in its scale. ** For doubles, that would be 1/2^52. ** (This method is not bulletproof: there may be another float ** with that value, and for floats la

Source from the content-addressed store, hash-verified

601** a duplicate.)
602*/
603static int luaK_numberK (FuncState *fs, lua_Number r) {
604 TValue o;
605 lua_Integer ik;
606 setfltvalue(&o, r);
607 if (!luaV_flttointeger(r, &ik, F2Ieq)) /* not an integral value? */
608 return addk(fs, &o, &o); /* use number itself as key */
609 else { /* must build an alternative key */
610 const int nbm = l_floatatt(MANT_DIG);
611 const lua_Number q = l_mathop(ldexp)(l_mathop(1.0), -nbm + 1);
612 const lua_Number k = (ik == 0) ? q : r + r*q; /* new key */
613 TValue kv;
614 setfltvalue(&kv, k);
615 /* result is not an integral value, unless value is too large */
616 lua_assert(!luaV_flttointeger(k, &ik, F2Ieq) ||
617 l_mathop(fabs)(r) >= l_mathop(1e6));
618 return addk(fs, &kv, &o);
619 }
620}
621
622
623/*

Callers 2

luaK_floatFunction · 0.70
luaK_exp2KFunction · 0.70

Calls 2

luaV_flttointegerFunction · 0.70
addkFunction · 0.70

Tested by

no test coverage detected