aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-10-17 12:46:13 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-10-17 12:46:13 -0200
commit1350a2bcb59ffad48183241fa8f3f1cf31360f35 (patch)
treee5b7a4374e94d401a92d635fcb6f7a1cc31dc1e6
parent217e67cb224cbb9bd68a1bce7454b60d50894f79 (diff)
downloadlua-1350a2bcb59ffad48183241fa8f3f1cf31360f35.tar.gz
lua-1350a2bcb59ffad48183241fa8f3f1cf31360f35.tar.bz2
lua-1350a2bcb59ffad48183241fa8f3f1cf31360f35.zip
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...)
-rw-r--r--lobject.h56
1 files changed, 39 insertions, 17 deletions
diff --git a/lobject.h b/lobject.h
index 1f32e50f..921a910e 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 2.61 2011/07/04 20:29:02 roberto Exp roberto $ 2** $Id: lobject.h,v 2.62 2011/09/24 21:12:01 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -264,51 +264,73 @@ typedef struct lua_TValue TValue;
264** ======================================================= 264** =======================================================
265*/ 265*/
266 266
267#if defined(LUA_NANTRICKLE) || defined(LUA_NANTRICKBE) 267#if defined(LUA_NANTRICK) \
268 || defined(LUA_NANTRICK_LE) \
269 || defined(LUA_NANTRICK_BE)
268 270
269/* 271/*
270** numbers are represented in the 'd_' field. All other values have the 272** numbers are represented in the 'd_' field. All other values have the
271** value (NNMARK | tag) in 'tt_'. A number with such pattern would be 273** value (NNMARK | tag) in 'tt__'. A number with such pattern would be
272** a "signaled NaN", which is never generated by regular operations by 274** a "signaled NaN", which is never generated by regular operations by
273** the CPU (nor by 'strtod') 275** the CPU (nor by 'strtod')
274*/ 276*/
275#if !defined(NNMARK) 277#if !defined(NNMARK)
276#define NNMARK 0x7FF7A500 278#define NNMARK 0x7FF7A500
279#define NNMASK 0x7FFFFF00
277#endif 280#endif
278 281
279#undef TValuefields 282#undef TValuefields
280#undef NILCONSTANT 283#undef NILCONSTANT
281#if defined(LUA_NANTRICKLE) 284
285#if defined(LUA_NANTRICK_LE)
286
282/* little endian */ 287/* little endian */
283#define TValuefields \ 288#define TValuefields \
284 union { struct { Value v_; int tt_; } i; double d_; } u 289 union { struct { Value v__; int tt__; } i; double d__; } u
285#define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}} 290#define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}}
286#else 291/* field-access macros */
292#define v_(o) ((o)->u.i.v__)
293#define d_(o) ((o)->u.d__)
294#define tt_(o) ((o)->u.i.tt__)
295
296#elif defined(LUA_NANTRICK_BE)
297
287/* big endian */ 298/* big endian */
288#define TValuefields \ 299#define TValuefields \
289 union { struct { int tt_; Value v_; } i; double d_; } u 300 union { struct { int tt__; Value v__; } i; double d__; } u
290#define NILCONSTANT {{tag2tt(LUA_TNIL), {NULL}}} 301#define NILCONSTANT {{tag2tt(LUA_TNIL), {NULL}}}
302/* field-access macros */
303#define v_(o) ((o)->u.i.v__)
304#define d_(o) ((o)->u.d__)
305#define tt_(o) ((o)->u.i.tt__)
306
307#elif !defined(TValuefields)
308#error option 'LUA_NANTRICK' needs declaration for 'TValuefields'
309
291#endif 310#endif
292 311
312
313/* correspondence with standard representation */
314#undef val_
315#define val_(o) v_(o)
316#undef num_
317#define num_(o) d_(o)
318
319
293#undef numfield 320#undef numfield
294#define numfield /* no such field; numbers are the entire struct */ 321#define numfield /* no such field; numbers are the entire struct */
295 322
296/* basic check to distinguish numbers from non-numbers */ 323/* basic check to distinguish numbers from non-numbers */
297#undef ttisnumber 324#undef ttisnumber
298#define ttisnumber(o) (((o)->u.i.tt_ & 0x7fffff00) != NNMARK) 325#define ttisnumber(o) ((tt_(o) & NNMASK) != NNMARK)
299 326
300#define tag2tt(t) (NNMARK | (t)) 327#define tag2tt(t) (NNMARK | (t))
301 328
302#undef val_
303#define val_(o) ((o)->u.i.v_)
304#undef num_
305#define num_(o) ((o)->u.d_)
306
307#undef rttype 329#undef rttype
308#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : (o)->u.i.tt_ & 0xff) 330#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : tt_(o) & 0xff)
309 331
310#undef settt_ 332#undef settt_
311#define settt_(o,t) ((o)->u.i.tt_=tag2tt(t)) 333#define settt_(o,t) (tt_(o) = tag2tt(t))
312 334
313#undef setnvalue 335#undef setnvalue
314#define setnvalue(obj,x) \ 336#define setnvalue(obj,x) \
@@ -326,11 +348,11 @@ typedef struct lua_TValue TValue;
326*/ 348*/
327 349
328#undef checktag 350#undef checktag
329#define checktag(o,t) ((o)->u.i.tt_ == tag2tt(t)) 351#define checktag(o,t) (tt_(o) == tag2tt(t))
330 352
331#undef ttisequal 353#undef ttisequal
332#define ttisequal(o1,o2) \ 354#define ttisequal(o1,o2) \
333 (ttisnumber(o1) ? ttisnumber(o2) : ((o1)->u.i.tt_ == (o2)->u.i.tt_)) 355 (ttisnumber(o1) ? ttisnumber(o2) : (tt_(o1) == tt_(o2)))
334 356
335 357
336 358