lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Jul 9, 2013, at 8:33 PM, Miles Bader <miles@gnu.org> wrote:

> William Ahern <william@25thandClement.com> writes:
>> One quibble: most protocols sanely use unsigned integers. A signed 64-bit
>> integer is 1 bit too short, and generally speaking you're not much better
>> off than with floating point doubles and the bit32 library.
> 
> It sort of depends on what you're doing with them.  For many uses,
> even if the "real" type is an unsigned integer, a signed integer with
> guaranteed twos-complement overflow/wraparound behavior (as in Lua
> 5.3) will work just fine.
> 
> That's one reason their choice of semantics for overflow are really
> pretty nice.

Yes. In fact, I can't think of any use of full 64-bit unsigned integer that won't "work just fine." We can even read and write them:

> return 9223372036854775809
-9223372036854775807
> return string.format("%u",-9223372036854775807)
9223372036854775809

> return string.format("%u",9223372036854775809)
9223372036854775809

> =2^64-1
-1
> return string.format("%u",-1)
18446744073709551615

> return string.format("%u",18446744073709551615)
18446744073709551615

e