diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-06-09 15:21:25 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-06-09 15:21:25 -0300 |
| commit | 35391d9b1aab036f37799458236e0ea0ca4a4d3f (patch) | |
| tree | 2f968c897f0bb9b446d37667913fbc14ad17969b | |
| parent | 99b1b8e9186c05cc02385b943bc0570426b0f19e (diff) | |
| download | lua-35391d9b1aab036f37799458236e0ea0ca4a4d3f.tar.gz lua-35391d9b1aab036f37799458236e0ea0ca4a4d3f.tar.bz2 lua-35391d9b1aab036f37799458236e0ea0ca4a4d3f.zip | |
macro 'NNMARK' (mark for non-number values using the NaN trick)
| -rw-r--r-- | lobject.h | 10 |
1 files changed, 6 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 2.57 2011/06/02 19:31:40 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.58 2011/06/07 19:02:33 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 | */ |
| @@ -266,10 +266,12 @@ typedef struct lua_TValue TValue; | |||
| 266 | 266 | ||
| 267 | /* | 267 | /* |
| 268 | ** numbers are represented in the 'd_' field. All other values have the | 268 | ** numbers are represented in the 'd_' field. All other values have the |
| 269 | ** value (0x7ff70000 | tag) in 'tt_'. A number with such pattern would be | 269 | ** value (NNMARK | tag) in 'tt_'. A number with such pattern would be |
| 270 | ** a "signaled NaN", which is never generated by regular operations by | 270 | ** a "signaled NaN", which is never generated by regular operations by |
| 271 | ** the CPU (nor by 'strtod') | 271 | ** the CPU (nor by 'strtod') |
| 272 | */ | 272 | */ |
| 273 | #define NNMARK 0x7FF7A500 | ||
| 274 | |||
| 273 | #undef TValuefields | 275 | #undef TValuefields |
| 274 | #define TValuefields \ | 276 | #define TValuefields \ |
| 275 | union { struct { Value v_; int tt_; } i; double d_; } u | 277 | union { struct { Value v_; int tt_; } i; double d_; } u |
| @@ -279,9 +281,9 @@ typedef struct lua_TValue TValue; | |||
| 279 | 281 | ||
| 280 | /* basic check to distinguish numbers from non-numbers */ | 282 | /* basic check to distinguish numbers from non-numbers */ |
| 281 | #undef ttisnumber | 283 | #undef ttisnumber |
| 282 | #define ttisnumber(o) (((o)->u.i.tt_ & 0x7fff0000) != 0x7ff70000) | 284 | #define ttisnumber(o) (((o)->u.i.tt_ & 0x7fffff00) != NNMARK) |
| 283 | 285 | ||
| 284 | #define tag2tt(t) (0x7ff70000 | (t)) | 286 | #define tag2tt(t) (NNMARK | (t)) |
| 285 | 287 | ||
| 286 | #undef NILCONSTANT | 288 | #undef NILCONSTANT |
| 287 | #define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}} | 289 | #define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}} |
