The math.maxinteger constant represents the maximum value that can be stored in an integer type in lua.

Syntax

math.maxinteger

Return value

Returns the maximum integer value, typically represented as a constant. This value is implementation-dependent but is guaranteed to be at least 2^53 - 1 for systems that use double-precision floating-point numbers to represent integers.

Description

math.maxinteger is a predefined constant in lua that signifies the largest integer that can be safely represented without loss of precision. It is particularly useful for performing arithmetic operations that involve large integers to ensure that they do not exceed the representable range.

Examples

Using math.maxinteger

print(math.maxinteger)                -- Output: 9223372036854775807 (or the equivalent maximum integer value)

Comparison with other integers

local bigNumber = math.maxinteger + 1
print(bigNumber)                       -- Output may vary, could result in a number that cannot be represented as an integer
print(bigNumber == math.maxinteger + 1) -- false, as it exceeds maxinteger

See also

  • math.max
  • math.mininteger
  • math.min

Was this page helpful?

Table of Contents