math.maxinteger

Shared

The maximum value a Lua integer can hold


Constant

math.maxinteger -- 9223372036854775807

Represents the largest integer value representable by Lua's 64-bit signed integer type (2^63 - 1).


Examples

Print the maximum integer value
engine.print("info", math.maxinteger) -- 9223372036854775807
maxinteger plus 1 wraps around to mininteger
local result = math.maxinteger + 1

engine.print("info", result) -- -9223372036854775808
Use as an upper sentinel for minimum searching
local values = {100, 200, 50, 400}
local smallest = math.maxinteger

for _, v in ipairs(values) do
    if v < smallest then smallest = v end
end

engine.print("info", smallest) -- 50
Check if a value equals the integer ceiling
local value = math.maxinteger

engine.print("info", math.type(value) == "integer") -- true
engine.print("info", value == math.maxinteger)      -- true
Compute the usable bit width of the integer type
local bits = math.floor(math.log(math.maxinteger, 2)) + 1

engine.print("info", bits) -- 63

On this page