Hi, I've been trying to implement LCG[1] in Lua, but I've encountered a strange issue: print((-2740105712118473000) * 0x5851F42D4C957F2D) This code prints '-6111441440935226376' even tho the expected result is '12335302632774325240'.
Both numbers have the same 64-bit representation (one is signed,
the other one is unsigned).
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/lua-l/467bf1c1-1e32-4fc5-abcc-56ec1547346e%40cdelord.fr.
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
The first negative décimal number results in a 64-bit double with overflowing but with some precision loss, so the negative sign is preserved. The second hexadecimal number is a 64bit integer. The multiplication converts the second number to a 64-bit double, keeping its positive sign and the result is a negative 64-bit double.