1
0
mirror of https://github.com/lua/lua.git synced 2025-01-28 06:03:00 +08:00

macro 'NNMARK' (mark for non-number values using the NaN trick)

This commit is contained in:
Roberto Ierusalimschy 2011-06-09 15:21:25 -03:00
parent 99b1b8e918
commit 35391d9b1a

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lobject.h,v 2.57 2011/06/02 19:31:40 roberto Exp roberto $ ** $Id: lobject.h,v 2.58 2011/06/07 19:02:33 roberto Exp roberto $
** Type definitions for Lua objects ** Type definitions for Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -266,10 +266,12 @@ typedef struct lua_TValue TValue;
/* /*
** numbers are represented in the 'd_' field. All other values have the ** numbers are represented in the 'd_' field. All other values have the
** value (0x7ff70000 | tag) in 'tt_'. A number with such pattern would be ** value (NNMARK | tag) in 'tt_'. A number with such pattern would be
** a "signaled NaN", which is never generated by regular operations by ** a "signaled NaN", which is never generated by regular operations by
** the CPU (nor by 'strtod') ** the CPU (nor by 'strtod')
*/ */
#define NNMARK 0x7FF7A500
#undef TValuefields #undef TValuefields
#define TValuefields \ #define TValuefields \
union { struct { Value v_; int tt_; } i; double d_; } u union { struct { Value v_; int tt_; } i; double d_; } u
@ -279,9 +281,9 @@ typedef struct lua_TValue TValue;
/* basic check to distinguish numbers from non-numbers */ /* basic check to distinguish numbers from non-numbers */
#undef ttisnumber #undef ttisnumber
#define ttisnumber(o) (((o)->u.i.tt_ & 0x7fff0000) != 0x7ff70000) #define ttisnumber(o) (((o)->u.i.tt_ & 0x7fffff00) != NNMARK)
#define tag2tt(t) (0x7ff70000 | (t)) #define tag2tt(t) (NNMARK | (t))
#undef NILCONSTANT #undef NILCONSTANT
#define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}} #define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}}