lua-users home
lua-l archive

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


On Jan 10, 2012, at 4:24 PM, Dirk Laurie wrote:

>> If two string is not same length, then how to define these binary operations?
>> 
> Two possiblities:
> 
>  - it is an error
>  - the shorter string defines the length of the result

There are two more possibilities 

- treat the "strings" as unsigned binary numbers (lsb in byte 0) and zero extend the shorter string

- treat the "strings" as signed binary numbers (lsb in byte 0) and sign extend the shorter string

This opens up the possibility of using the same userdata type, or providing identity conversions, to implement bignums. I prefer the signed version because it is a compact means of representing bignums (as opposed to sign and magnitude) and compatible with Common Lisp bit operation semantics on bignums.

e