diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-03-27 12:38:29 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-03-27 12:38:29 -0300 |
commit | ef5d171cc89b19ac1fea905b99d819b5f97cba00 (patch) | |
tree | bdc900455d00c0e8cfdcbb64993842a502fc9e21 /llimits.h | |
parent | b0f3df16a495745cf16657a48dde6845ec85c732 (diff) | |
download | lua-ef5d171cc89b19ac1fea905b99d819b5f97cba00.tar.gz lua-ef5d171cc89b19ac1fea905b99d819b5f97cba00.tar.bz2 lua-ef5d171cc89b19ac1fea905b99d819b5f97cba00.zip |
New macro 'l_numbits'
Diffstat (limited to 'llimits.h')
-rw-r--r-- | llimits.h | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -15,6 +15,8 @@ | |||
15 | #include "lua.h" | 15 | #include "lua.h" |
16 | 16 | ||
17 | 17 | ||
18 | #define l_numbits(t) cast_int(sizeof(t) * CHAR_BIT) | ||
19 | |||
18 | /* | 20 | /* |
19 | ** 'l_mem' is a signed integer big enough to count the total memory | 21 | ** 'l_mem' is a signed integer big enough to count the total memory |
20 | ** used by Lua. (It is signed due to the use of debt in several | 22 | ** used by Lua. (It is signed due to the use of debt in several |
@@ -33,7 +35,7 @@ typedef unsigned long lu_mem; | |||
33 | #endif /* } */ | 35 | #endif /* } */ |
34 | 36 | ||
35 | #define MAX_LMEM \ | 37 | #define MAX_LMEM \ |
36 | cast(l_mem, (cast(lu_mem, 1) << (sizeof(l_mem) * 8 - 1)) - 1) | 38 | cast(l_mem, (cast(lu_mem, 1) << (l_numbits(l_mem) - 1)) - 1) |
37 | 39 | ||
38 | 40 | ||
39 | /* chars used as small naturals (so that 'char' is reserved for characters) */ | 41 | /* chars used as small naturals (so that 'char' is reserved for characters) */ |
@@ -61,7 +63,7 @@ typedef lu_byte TStatus; | |||
61 | ** floor of the log2 of the maximum signed value for integral type 't'. | 63 | ** floor of the log2 of the maximum signed value for integral type 't'. |
62 | ** (That is, maximum 'n' such that '2^n' fits in the given signed type.) | 64 | ** (That is, maximum 'n' such that '2^n' fits in the given signed type.) |
63 | */ | 65 | */ |
64 | #define log2maxs(t) cast_int(sizeof(t) * 8 - 2) | 66 | #define log2maxs(t) (l_numbits(t) - 2) |
65 | 67 | ||
66 | 68 | ||
67 | /* | 69 | /* |