util.math.min

Shared

Returns the smallest value among the given arguments


Syntax

local result = util.math.min(
    value,
    ...
)

Parameters

TypeNameDescription
floatvalueFirst number
float...Additional numbers to compare

Returns

TypeNameDescription
floatresultThe smallest of all given values

Examples

Min of two numbers
local result = util.math.min(3, 7)

core.engine.print("info", result) -- 3
Min of multiple numbers
local result = util.math.min(10, 5, 8, 1, 6)

core.engine.print("info", result) -- 1
Min with negative numbers
local result = util.math.min(-1, -5, -3)

core.engine.print("info", result) -- -5
Min of a single value returns itself
local result = util.math.min(99)

core.engine.print("info", result) -- 99
Clamp a value to a maximum ceiling
local speed = 150
local clamped = util.math.min(speed, 100)

core.engine.print("info", clamped) -- 100
Clamp a value between a min and max
local value = 120
local clamped = util.math.max(0, util.math.min(value, 100))

core.engine.print("info", clamped) -- 100
Cap items rendered to available slots
local item_count = 25
local slot_count = 10
local render_count = util.math.min(item_count, slot_count)

core.engine.print("info", render_count) -- 10

On this page