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

Function luaK_numberK

third-party/lua-5.5.0/src/lcode.c:617–639  ·  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 end, we add to the number its smaller ** power-of-two fraction that is still significant in its scale. ** (For doubles, the fraction would be 2^-52). ** This method is not bulletproof: different numbers may generate the ** same key (e.g.

Source from the content-addressed store, hash-verified

615** with a duplicate.
616*/
617static int luaK_numberK (FuncState *fs, lua_Number r) {
618 TValue o, kv;
619 setfltvalue(&o, r); /* value as a TValue */
620 if (r == 0) { /* handle zero as a special case */
621 setpvalue(&kv, fs); /* use FuncState as index */
622 return k2proto(fs, &kv, &o); /* cannot collide */
623 }
624 else {
625 const int nbm = l_floatatt(MANT_DIG);
626 const lua_Number q = l_mathop(ldexp)(l_mathop(1.0), -nbm + 1);
627 const lua_Number k = r * (1 + q); /* key */
628 lua_Integer ik;
629 setfltvalue(&kv, k); /* key as a TValue */
630 if (!luaV_flttointeger(k, &ik, F2Ieq)) { /* not an integer value? */
631 int n = k2proto(fs, &kv, &o); /* use key */
632 if (luaV_rawequalobj(&fs->f->k[n], &o)) /* correct value? */
633 return n;
634 }
635 /* else, either key is still an integer or there was a collision;
636 anyway, do not try to reuse constant; instead, create a new one */
637 return addk(fs, fs->f, &o);
638 }
639}
640
641
642/*

Callers 2

luaK_floatFunction · 0.70
luaK_exp2KFunction · 0.70

Calls 3

k2protoFunction · 0.85
luaV_flttointegerFunction · 0.70
addkFunction · 0.70

Tested by

no test coverage detected