[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Unsigned Integer Literals?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 5 Dec 2018 09:46:38 -0200
> having not only unsigned integers but also the corresponding data type
> could be a good idea if one has to do integer arithmetic in that range
> since the bits representing negative integers would be used for
> positive integers and thus the possible range for pure integer
> arithmetic is extended.
You can go a long way using unsigned integers in Lua 5.3. For equality,
addition, subtraction, and multiplication, the standard operations do
the job. For constants, you better use hexadecimal. For printing, "%u"
does the job. For order, 'math.ult' does unsigned comparisons. Division
and conversions between floats and unsigned needs some more work, but
can be done. (For instance, "x % 2^64" converts an unsigned integer 'x'
PiL 4 has an entire section (13.2) dedicated to unsigned integers
(with the caveat about the change in decimal literals).