util.math.huge
Shared
A constant representing positive infinity
Constant
util.math.huge -- infRepresents positive infinity. Useful as a sentinel initial value for minimum-finding loops, or for comparisons involving unbounded ranges.
Examples
core.engine.print("info", util.math.huge) -- infcore.engine.print("info", util.math.huge > 1e308) -- truecore.engine.print("info", -util.math.huge < -1e308) -- truelocal values = {42, 7, 99, 3, 56}
local smallest = util.math.huge
for _, v in ipairs(values) do
if v < smallest then
smallest = v
end
end
core.engine.print("info", smallest) -- 3local values = {42, 7, 99, 3, 56}
local largest = -util.math.huge
for _, v in ipairs(values) do
if v > largest then
largest = v
end
end
core.engine.print("info", largest) -- 99local function is_finite(value)
return value > -util.math.huge and value < util.math.huge
end
core.engine.print("info", is_finite(42)) -- true
core.engine.print("info", is_finite(util.math.huge)) -- falselocal result = 1/0
core.engine.print("info", result == util.math.huge) -- true