/* ** Try to "constant-fold" an operation; return 1 iff successful */ static int constfolding (FuncState *fs, int op, expdesc *e1, expdesc *e2) { TValue v1, v2, res; if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2)) return 0; /* non-numeric operands or not safe to fold */ luaO_arith(fs->ls->L, op, &v1, &v2, &res); if (ttisinteger(&res)) { e1->k = VKINT; e1->u.ival = ivalue(&res); } else { lua_Number n = fltvalue(&res); if (luai_numisnan(n) || isminuszero(n)) return 0; /* folds neither NaN nor -0 */ e1->k = VKFLT; e1->u.nval = n; } return 1; }
/* ** Both NaN and -0.0 should not go to the constant table, as they have ** problems with the hashing. (NaN is not a valid key, -0.0 collides ** with +0.0.) */ static int luaK_numberK (FuncState *fs, lua_Number r) { TValue o; lua_assert(!luai_numisnan(r) && !isminuszero(r)); setfltvalue(&o, r); return addk(fs, &o, &o); }