diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-05-13 16:17:21 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-05-13 16:17:21 -0300 |
commit | 279c3a6961c60252f0368fdea889caf977f85fe0 (patch) | |
tree | 1614c0b508f34657f81d155dec6dffd92e671479 /lmathlib.c | |
parent | 49c42f3615bd876657bf697e3bf040ce796ae238 (diff) | |
download | lua-279c3a6961c60252f0368fdea889caf977f85fe0.tar.gz lua-279c3a6961c60252f0368fdea889caf977f85fe0.tar.bz2 lua-279c3a6961c60252f0368fdea889caf977f85fe0.zip |
A few changes in tests about number of bits in integers
- The preprocessor must work with at least 'long', and therefore must
do shifts of up to 31 bits correctly.
- Whenever possible, use unsigned types in shifts.
Diffstat (limited to 'lmathlib.c')
-rw-r--r-- | lmathlib.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -266,7 +266,7 @@ static int math_type (lua_State *L) { | |||
266 | 266 | ||
267 | /* try to find an integer type with at least 64 bits */ | 267 | /* try to find an integer type with at least 64 bits */ |
268 | 268 | ||
269 | #if (LONG_MAX >> 31 >> 31) >= 1 | 269 | #if (ULONG_MAX >> 31 >> 31) >= 3 |
270 | 270 | ||
271 | /* 'long' has at least 64 bits */ | 271 | /* 'long' has at least 64 bits */ |
272 | #define Rand64 unsigned long | 272 | #define Rand64 unsigned long |
@@ -276,7 +276,7 @@ static int math_type (lua_State *L) { | |||
276 | /* there is a 'long long' type (which must have at least 64 bits) */ | 276 | /* there is a 'long long' type (which must have at least 64 bits) */ |
277 | #define Rand64 unsigned long long | 277 | #define Rand64 unsigned long long |
278 | 278 | ||
279 | #elif (LUA_MAXINTEGER >> 31 >> 31) >= 1 | 279 | #elif (LUA_MAXINTEGER >> 30 >> 30) >= 7 |
280 | 280 | ||
281 | /* 'lua_Integer' has at least 64 bits */ | 281 | /* 'lua_Integer' has at least 64 bits */ |
282 | #define Rand64 lua_Unsigned | 282 | #define Rand64 lua_Unsigned |
@@ -347,7 +347,7 @@ static lua_Number I2d (Rand64 x) { | |||
347 | #else /* no 'Rand64' }{ */ | 347 | #else /* no 'Rand64' }{ */ |
348 | 348 | ||
349 | /* get an integer with at least 32 bits */ | 349 | /* get an integer with at least 32 bits */ |
350 | #if (INT_MAX >> 30) >= 1 | 350 | #if LUAI_IS32INT |
351 | typedef unsigned int lu_int32; | 351 | typedef unsigned int lu_int32; |
352 | #else | 352 | #else |
353 | typedef unsigned long lu_int32; | 353 | typedef unsigned long lu_int32; |
@@ -538,7 +538,7 @@ static lua_Unsigned project (lua_Unsigned ran, lua_Unsigned n, | |||
538 | lim |= (lim >> 4); | 538 | lim |= (lim >> 4); |
539 | lim |= (lim >> 8); | 539 | lim |= (lim >> 8); |
540 | lim |= (lim >> 16); | 540 | lim |= (lim >> 16); |
541 | #if (LUA_MAXINTEGER >> 30 >> 1) > 0 | 541 | #if (LUA_MAXINTEGER >> 30) >= 3 |
542 | lim |= (lim >> 32); /* integer type has more than 32 bits */ | 542 | lim |= (lim >> 32); /* integer type has more than 32 bits */ |
543 | #endif | 543 | #endif |
544 | } | 544 | } |