]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
FFI: Add macros for consistent number to integer truncation.
authorMike Pall <mike>
Fri, 26 Nov 2010 12:40:40 +0000 (13:40 +0100)
committerMike Pall <mike>
Fri, 26 Nov 2010 12:40:40 +0000 (13:40 +0100)
src/lj_obj.h

index 83e30b6ee390eee4284cfa63eb71c3927010020f..b417dce76ce0e61b763d9407bb65248c2fea3920 100644 (file)
@@ -761,6 +761,13 @@ static LJ_AINLINE int32_t lj_num2bit(lua_Number n)
 #define lj_num2int(n)   ((int32_t)(n))
 #endif
 
+/* Truncate towards zero. */
+#define lj_trnum2int32(n)      ((int32_t)(n))
+#define lj_trnum2uint32(n)     ((uint32_t)(n))
+#define lj_trnum2int64(n)      ((int64_t)(n))
+#define lj_trnum2uint64(n) \
+  ((uint64_t)(int64_t)((n)- 9223372036854775808.0) + U64x(80000000,00000000))
+
 /* -- Miscellaneous object handling --------------------------------------- */
 
 /* Names and maps for internal and external object tags. */