aboutsummaryrefslogtreecommitdiff
path: root/llimits.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2012-05-11 11:10:50 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2012-05-11 11:10:50 -0300
commit77cbd817d1a525a161f8f24e98459191edb9a181 (patch)
tree0a5c621a34772b73b3b52559afccdc6decce9afa /llimits.h
parent4ec7d6de95bcf9fa35a9b268a41154b142190691 (diff)
downloadlua-77cbd817d1a525a161f8f24e98459191edb9a181.tar.gz
lua-77cbd817d1a525a161f8f24e98459191edb9a181.tar.bz2
lua-77cbd817d1a525a161f8f24e98459191edb9a181.zip
better(?) handling of '#define's for IEEE-related tricks + avoid using
IEEE trick for 64-bit integer types (lua_Integer on 64-bit machines)
Diffstat (limited to 'llimits.h')
-rw-r--r--llimits.h15
1 files changed, 10 insertions, 5 deletions
diff --git a/llimits.h b/llimits.h
index 2a7761b4..2397fc3f 100644
--- a/llimits.h
+++ b/llimits.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llimits.h,v 1.96 2012/01/25 21:05:40 roberto Exp roberto $ 2** $Id: llimits.h,v 1.97 2012/03/28 18:27:25 roberto Exp roberto $
3** Limits, basic types, and some other `installation-dependent' definitions 3** Limits, basic types, and some other `installation-dependent' definitions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -209,31 +209,36 @@ typedef lu_int32 Instruction;
209 209
210#elif defined(LUA_IEEE754TRICK) /* }{ */ 210#elif defined(LUA_IEEE754TRICK) /* }{ */
211/* the next trick should work on any machine using IEEE754 with 211/* the next trick should work on any machine using IEEE754 with
212 a 32-bit integer type */ 212 a 32-bit int type */
213 213
214union luai_Cast { double l_d; LUA_INT32 l_p[2]; }; 214union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
215 215
216#if !defined(LUA_IEEEENDIAN) /* { */ 216#if !defined(LUA_IEEEENDIAN) /* { */
217#define LUAI_EXTRAIEEE \ 217#define LUAI_EXTRAIEEE \
218 static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)}; 218 static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
219#define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33) 219#define LUA_IEEEENDIANLOC (ieeeendian.l_p[1] == 33)
220#else 220#else
221#define LUA_IEEEENDIANLOC LUA_IEEEENDIAN
221#define LUAI_EXTRAIEEE /* empty */ 222#define LUAI_EXTRAIEEE /* empty */
222#endif /* } */ 223#endif /* } */
223 224
224#define lua_number2int32(i,n,t) \ 225#define lua_number2int32(i,n,t) \
225 { LUAI_EXTRAIEEE \ 226 { LUAI_EXTRAIEEE \
226 volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \ 227 volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
227 (i) = (t)u.l_p[LUA_IEEEENDIAN]; } 228 (i) = (t)u.l_p[LUA_IEEEENDIANLOC]; }
228 229
229#define luai_hashnum(i,n) \ 230#define luai_hashnum(i,n) \
230 { volatile union luai_Cast u; u.l_d = (n) + 1.0; /* avoid -0 */ \ 231 { volatile union luai_Cast u; u.l_d = (n) + 1.0; /* avoid -0 */ \
231 (i) = u.l_p[0]; (i) += u.l_p[1]; } /* add double bits for his hash */ 232 (i) = u.l_p[0]; (i) += u.l_p[1]; } /* add double bits for his hash */
232 233
233#define lua_number2int(i,n) lua_number2int32(i, n, int) 234#define lua_number2int(i,n) lua_number2int32(i, n, int)
234#define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer)
235#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned) 235#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
236 236
237/* the trick can be expanded to lua_Integer when it is a 32-bit value */
238#if defined(LUA_IEEELL)
239#define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer)
240#endif
241
237#endif /* } */ 242#endif /* } */
238 243
239 244