MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaK_numberK

Function luaK_numberK

lib/lua/src/lcode.c:602–619  ·  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

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

Callers 2

luaK_floatFunction · 0.85
luaK_exp2KFunction · 0.85

Calls 2

luaV_flttointegerFunction · 0.85
addkFunction · 0.85

Tested by

no test coverage detected