diff options
| -rw-r--r-- | llimits.h | 21 |
1 files changed, 11 insertions, 10 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llimits.h,v 1.82 2010/05/31 16:08:55 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.83 2010/11/03 15:16:17 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 | */ |
| @@ -170,9 +170,9 @@ typedef lu_int32 Instruction; | |||
| 170 | 170 | ||
| 171 | /* | 171 | /* |
| 172 | ** lua_number2int is a macro to convert lua_Number to int. | 172 | ** lua_number2int is a macro to convert lua_Number to int. |
| 173 | ** lua_number2integer is a macro to convert lua_Number to LUA_INTEGER. | 173 | ** lua_number2integer is a macro to convert lua_Number to lua_Integer. |
| 174 | ** lua_number2unsigned is a macro to convert a lua_Number to a LUA_UNSIGNED. | 174 | ** lua_number2unsigned is a macro to convert a lua_Number to a lua_Unsigned. |
| 175 | ** lua_unsigned2number is a macro to convert a LUA_UNSIGNED to a lua_Number. | 175 | ** lua_unsigned2number is a macro to convert a lua_Unsigned to a lua_Number. |
| 176 | */ | 176 | */ |
| 177 | 177 | ||
| 178 | #if defined(MS_ASMTRICK) /* { */ | 178 | #if defined(MS_ASMTRICK) /* { */ |
| @@ -204,8 +204,8 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; }; | |||
| 204 | (i) = (t)u.l_p[LUA_IEEEENDIAN]; } | 204 | (i) = (t)u.l_p[LUA_IEEEENDIAN]; } |
| 205 | 205 | ||
| 206 | #define lua_number2int(i,n) lua_number2int32(i, n, int) | 206 | #define lua_number2int(i,n) lua_number2int32(i, n, int) |
| 207 | #define lua_number2integer(i,n) lua_number2int32(i, n, LUA_INTEGER) | 207 | #define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer) |
| 208 | #define lua_number2unsigned(i,n) lua_number2int32(i, n, LUA_UNSIGNED) | 208 | #define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned) |
| 209 | 209 | ||
| 210 | #endif /* } */ | 210 | #endif /* } */ |
| 211 | 211 | ||
| @@ -217,17 +217,18 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; }; | |||
| 217 | #endif | 217 | #endif |
| 218 | 218 | ||
| 219 | #if !defined(lua_number2integer) | 219 | #if !defined(lua_number2integer) |
| 220 | #define lua_number2integer(i,n) ((i)=(LUA_INTEGER)(n)) | 220 | #define lua_number2integer(i,n) ((i)=(lua_Integer)(n)) |
| 221 | #endif | 221 | #endif |
| 222 | 222 | ||
| 223 | #if !defined(lua_number2unsigned) /* { */ | 223 | #if !defined(lua_number2unsigned) /* { */ |
| 224 | /* the following definition assures proper modulo behavior */ | 224 | /* the following definition assures proper modulo behavior */ |
| 225 | #if defined(LUA_NUMBER_DOUBLE) | 225 | #if defined(LUA_NUMBER_DOUBLE) |
| 226 | #include <math.h> | 226 | #include <math.h> |
| 227 | #define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1) | ||
| 227 | #define lua_number2unsigned(i,n) \ | 228 | #define lua_number2unsigned(i,n) \ |
| 228 | ((i)=(LUA_UNSIGNED)((n) - floor((n)/4294967296.0)*4294967296.0)) | 229 | ((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED)) |
| 229 | #else | 230 | #else |
| 230 | #define lua_number2unsigned(i,n) ((i)=(LUA_UNSIGNED)(n)) | 231 | #define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n)) |
| 231 | #endif | 232 | #endif |
| 232 | #endif /* } */ | 233 | #endif /* } */ |
| 233 | 234 | ||
| @@ -236,7 +237,7 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; }; | |||
| 236 | /* on several machines, coercion from unsigned to double is slow, | 237 | /* on several machines, coercion from unsigned to double is slow, |
| 237 | so it may be worth to avoid */ | 238 | so it may be worth to avoid */ |
| 238 | #define lua_unsigned2number(u) \ | 239 | #define lua_unsigned2number(u) \ |
| 239 | ((LUA_INT32)(u) < 0 ? (lua_Number)(u) : (lua_Number)(LUA_INT32)(u)) | 240 | (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u)) |
| 240 | #endif | 241 | #endif |
| 241 | 242 | ||
| 242 | 243 | ||
