util.math.maxinteger

Shared

The maximum value a Lua integer can hold


Constant

util.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
core.engine.print("info", util.math.maxinteger) -- 9223372036854775807
maxinteger plus 1 wraps around to mininteger
local result = util.math.maxinteger + 1

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

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

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

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

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

On this page