Michael:
On Tue, 10 Jun 2025 at 18:45, Michael Bonnet <
maab...@gmail.com> wrote:
> I am working on a C API to an embedded system for use in Lua scripting. I have values I need to be able to return to the Lua VM that are 64 bit unsigned integers, and possibly reach into the range that is only representable by the full range of 64 bits. I need the value to not just be readable, but to be usable in arithmetic operations, on the Lua side.
> What is the canonical/common way to do this?
Which arithmetic operations do you needed? It is already been pointed
that addition, subtraction and multiplication work. Equality too.
Comparison is trivial to do in a little function ( negative greater
than non-negative, else normal comparison, IIRC ) and my udivmod is
... thirty lines with comments without pushing it.
Decimal printing may need a bit of work, but with a couple
substractions should be easy....
2^64-1 18446744073709551615
> a=0xffffffffffffffff
> a=-1
> b=0
> c=1000000000000000000
> while(a<0 or a>=c) do b=b+1 a=a-c print(a,b) end
-1000000000000000001 1
-2000000000000000001 2
-3000000000000000001 3
-4000000000000000001 4
-5000000000000000001 5
-6000000000000000001 6
-7000000000000000001 7
-8000000000000000001 8
-9000000000000000001 9
8446744073709551615 10
7446744073709551615 11
6446744073709551615 12
5446744073709551615 13
4446744073709551615 14
3446744073709551615 15
2446744073709551615 16
1446744073709551615 17
446744073709551615 18
It can be done better, just testing it.
Francisco Olarte.