lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Apr 27, 2015 at 6:53 AM, Emeka <emekamicro@gmail.com> wrote:
> Hello All,
>
> It looks like there  is something I am missing or not able to understand ...
>
> If n is Lua_Number, and k is just a cast of n LUA_Number to int, and
> cast_num just cast k back to LUA_Number, then the the if statement is
> redundant because they (n , k) would also be same. Could someone help figure
> out what I am missing ?  Function name const TValue *luaH_get,
>
>     case LUA_TNUMBER: {
>       int k;
>       lua_Number n = nvalue(key);
>       lua_number2int(k, n);
>       if (luai_numeq(cast_num(k), n)) /* index is int? */
>         return luaH_getint(t, k);  /* use specialized version */
>       /* else go through */
>     }
>
> Emeka
> --
> P.S Please join our groups:  nigeriaarduinogroup@googlegroups.com
>  or jifunze-kufikiria@googlegroups.com  These are platforms for learning and
> sharing  of knowledge.
> www.satajanus.com | Satajanus  Nig. Ltd
>
>

That's a check to see if you're looking at an integer-valued float --
it round-trips the value to see if it's unchanged. Imagine the case if
n were 3.5 -- then k would be 3, and float(3) != 3.5.

/s/ Adam