From 35391d9b1aab036f37799458236e0ea0ca4a4d3f Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 9 Jun 2011 15:21:25 -0300 Subject: [PATCH] macro 'NNMARK' (mark for non-number values using the NaN trick) --- lobject.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lobject.h b/lobject.h index 1d8bd64d..c130dcb6 100644 --- a/lobject.h +++ b/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 ** 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 -** 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 ** the CPU (nor by 'strtod') */ +#define NNMARK 0x7FF7A500 + #undef TValuefields #define TValuefields \ 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 */ #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 #define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}}