more macros to try to make NaN trick work with other sizes of

IEEE float numbers. (It has not been tested with such different
sizes...)
This commit is contained in:
Roberto Ierusalimschy 2011-10-17 12:46:13 -02:00
parent 217e67cb22
commit 1350a2bcb5
1 changed files with 39 additions and 17 deletions

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lobject.h,v 2.61 2011/07/04 20:29:02 roberto Exp roberto $ ** $Id: lobject.h,v 2.62 2011/09/24 21:12:01 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
*/ */
@ -264,51 +264,73 @@ typedef struct lua_TValue TValue;
** ======================================================= ** =======================================================
*/ */
#if defined(LUA_NANTRICKLE) || defined(LUA_NANTRICKBE) #if defined(LUA_NANTRICK) \
|| defined(LUA_NANTRICK_LE) \
|| defined(LUA_NANTRICK_BE)
/* /*
** 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 (NNMARK | 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')
*/ */
#if !defined(NNMARK) #if !defined(NNMARK)
#define NNMARK 0x7FF7A500 #define NNMARK 0x7FF7A500
#define NNMASK 0x7FFFFF00
#endif #endif
#undef TValuefields #undef TValuefields
#undef NILCONSTANT #undef NILCONSTANT
#if defined(LUA_NANTRICKLE)
#if defined(LUA_NANTRICK_LE)
/* little endian */ /* little endian */
#define TValuefields \ #define TValuefields \
union { struct { Value v_; int tt_; } i; double d_; } u union { struct { Value v__; int tt__; } i; double d__; } u
#define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}} #define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}}
#else /* field-access macros */
#define v_(o) ((o)->u.i.v__)
#define d_(o) ((o)->u.d__)
#define tt_(o) ((o)->u.i.tt__)
#elif defined(LUA_NANTRICK_BE)
/* big endian */ /* big endian */
#define TValuefields \ #define TValuefields \
union { struct { int tt_; Value v_; } i; double d_; } u union { struct { int tt__; Value v__; } i; double d__; } u
#define NILCONSTANT {{tag2tt(LUA_TNIL), {NULL}}} #define NILCONSTANT {{tag2tt(LUA_TNIL), {NULL}}}
/* field-access macros */
#define v_(o) ((o)->u.i.v__)
#define d_(o) ((o)->u.d__)
#define tt_(o) ((o)->u.i.tt__)
#elif !defined(TValuefields)
#error option 'LUA_NANTRICK' needs declaration for 'TValuefields'
#endif #endif
/* correspondence with standard representation */
#undef val_
#define val_(o) v_(o)
#undef num_
#define num_(o) d_(o)
#undef numfield #undef numfield
#define numfield /* no such field; numbers are the entire struct */ #define numfield /* no such field; numbers are the entire struct */
/* 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_ & 0x7fffff00) != NNMARK) #define ttisnumber(o) ((tt_(o) & NNMASK) != NNMARK)
#define tag2tt(t) (NNMARK | (t)) #define tag2tt(t) (NNMARK | (t))
#undef val_
#define val_(o) ((o)->u.i.v_)
#undef num_
#define num_(o) ((o)->u.d_)
#undef rttype #undef rttype
#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : (o)->u.i.tt_ & 0xff) #define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : tt_(o) & 0xff)
#undef settt_ #undef settt_
#define settt_(o,t) ((o)->u.i.tt_=tag2tt(t)) #define settt_(o,t) (tt_(o) = tag2tt(t))
#undef setnvalue #undef setnvalue
#define setnvalue(obj,x) \ #define setnvalue(obj,x) \
@ -326,11 +348,11 @@ typedef struct lua_TValue TValue;
*/ */
#undef checktag #undef checktag
#define checktag(o,t) ((o)->u.i.tt_ == tag2tt(t)) #define checktag(o,t) (tt_(o) == tag2tt(t))
#undef ttisequal #undef ttisequal
#define ttisequal(o1,o2) \ #define ttisequal(o1,o2) \
(ttisnumber(o1) ? ttisnumber(o2) : ((o1)->u.i.tt_ == (o2)->u.i.tt_)) (ttisnumber(o1) ? ttisnumber(o2) : (tt_(o1) == tt_(o2)))