Преглед изворни кода

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

Roberto Ierusalimschy пре 14 година
родитељ
комит
35391d9b1a
1 измењених фајлова са 6 додато и 4 уклоњено
  1. 6 4
      lobject.h

+ 6 - 4
lobject.h

@@ -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)}}