[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: int64 support in 64bit architecture
- From: Sam Roberts <vieuxtech@...>
- Date: Thu, 12 Apr 2012 11:59:46 -0700
2012/4/12 云风 <cloudwu@gmail.com>:
> Another example is unique id .
>
> The service allocate unique id consecutively , but it is not from 1 .
> It needs request the range from other service first. The range is
> defined by 64bit integer.
I'm not saying it's better for you, but another way of dealing with
int64 and uint64 that you
might consider (this is what I've done) is to encode them as strings
(either decimal, or 0x......),
and then write a small lib that does math on either strings or lua
numbers. This is kindof in
keeping with the lua behaviour of silently converting strings to numbers:
> = 5 + "4"
9
You can't use lua's mathematical operators without rounding (but you
can't use math operators
with your lightuserdata, either), but you can pass the strings to your
library, and do signed/unsigned
arithmetic on them after exact conversion to 64 bit C types:
local big = require"big64"
> = "18446744072277895850" + 1
1.8446744072278e+19
> = big.plus("18446744072277895850", 1)
"18446744072277895851"
Upside to this is its really easy to pass the values around (they are
strings), they print nicely
in debug output (as opposed to userdata:...), they can be used
(sloppily) with lua math operators
when you don't care about exact operations, etc.
Cheers,
Sam
- References:
- int64 support in 64bit architecture, 云风
- Re: int64 support in 64bit architecture, liam mail
- Re: int64 support in 64bit architecture, CHU Run-min
- Re: int64 support in 64bit architecture, steve donovan
- Re: int64 support in 64bit architecture, Alex Queiroz
- Re: int64 support in 64bit architecture, steve donovan
- Re: int64 support in 64bit architecture, Xavier Wang
- Re: int64 support in 64bit architecture, 云风
- Re: int64 support in 64bit architecture, Xavier Wang
- Re: int64 support in 64bit architecture, 云风
- Re: int64 support in 64bit architecture, Xavier Wang
- Re: int64 support in 64bit architecture, 云风
- Re: int64 support in 64bit architecture, Xavier Wang
- Re: int64 support in 64bit architecture, 云风