diff options
author | Mike Pall <mike> | 2010-11-26 13:40:40 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2010-11-26 13:40:40 +0100 |
commit | ef8c264873ee6f88651699ebbbd15bc1c5065ef2 (patch) | |
tree | 4817bb47f4cf1225ca7e25c4df5ec5e82584c5c1 /src | |
parent | 2fd129295555300ac01b17679a6ea4edee2173d2 (diff) | |
download | luajit-ef8c264873ee6f88651699ebbbd15bc1c5065ef2.tar.gz luajit-ef8c264873ee6f88651699ebbbd15bc1c5065ef2.tar.bz2 luajit-ef8c264873ee6f88651699ebbbd15bc1c5065ef2.zip |
FFI: Add macros for consistent number to integer truncation.
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_obj.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/lj_obj.h b/src/lj_obj.h index 83e30b6e..b417dce7 100644 --- a/src/lj_obj.h +++ b/src/lj_obj.h | |||
@@ -761,6 +761,13 @@ static LJ_AINLINE int32_t lj_num2bit(lua_Number n) | |||
761 | #define lj_num2int(n) ((int32_t)(n)) | 761 | #define lj_num2int(n) ((int32_t)(n)) |
762 | #endif | 762 | #endif |
763 | 763 | ||
764 | /* Truncate towards zero. */ | ||
765 | #define lj_trnum2int32(n) ((int32_t)(n)) | ||
766 | #define lj_trnum2uint32(n) ((uint32_t)(n)) | ||
767 | #define lj_trnum2int64(n) ((int64_t)(n)) | ||
768 | #define lj_trnum2uint64(n) \ | ||
769 | ((uint64_t)(int64_t)((n)- 9223372036854775808.0) + U64x(80000000,00000000)) | ||
770 | |||
764 | /* -- Miscellaneous object handling --------------------------------------- */ | 771 | /* -- Miscellaneous object handling --------------------------------------- */ |
765 | 772 | ||
766 | /* Names and maps for internal and external object tags. */ | 773 | /* Names and maps for internal and external object tags. */ |