Reputation: 7359
I'm reading "Programming in Lua, Forth Edition", and I'm stuck on exercise 13.1, because Lua does not seem to behave like in the book. The section 13.2, about Unsigned Integers, states:
> x = 13835058055282163712 -- 3ul << 62ul
> x --> -4611686018427387904
But if I do that in Lua 5.4, Windows x64, or Lua 5.3, WSL x64, they both behave like this:
> x = 13835058055282163712
> x
1.3835058055282e+19
> math.type(x)
float
So, I have 2 questions:
Upvotes: 3
Views: 167
Reputation: 1898
At the time the book was written (it corresponds to Lua version 5.3.0) Lua had wrong behavior of reading long integer literals: it wraparounded them.
Later, in Lua 5.3.3 this behavior has been corrected to a more user-friendly.
As for now, when a decimal integer literal in beyond int64 range, Lua reads it as float number to preserve its numeric value. Hexadecimal integer literals are wraparounded.
Upvotes: 3