edubart / lua-bint

Arbitrary precision integer arithmetic library in pure Lua

Home Page:https://edubart.github.io/lua-bint/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test of integer size in a loop is really necessary?

ReallyNiceGuy opened this issue · comments

Hi.
Not really an issue, just a question.
On luainteger_bitsize, you run a loop with a step of 1.
From what I understand, in Lua, an Integer can be only 32 or 64 bits. Why not use a step of 32?
Or even:

local function luainteger_bitsize()
  if -1>>32 == 0 then
    return 32
  end
  return 64
end

Cheers.

The lua integer can be one of the following C data types:

Although I find very unlikely anyone runs Lua in a machine where int is 16 bits or long long is greater than 64 bits.
The algorithm used there is not very important, because it's not a hot code path as it's called only once on the module setup. But anyway I have made the function step in 16 bits at least.