local intchecktbl = {
	['number'] = function(x)
		return x
	end,
	['string'] = function(x)
		return tonumber(x)
	end
}
if type(min) ~= 'function' then
	---@param a integer
	---@param b integer
	---@return integer|nil smallestNum
	---returns either `a` or `b` depending on which is smaller
	local function min(a, b)
		if not (intchecktbl[type(a)] or intchecktbl[type(b)]) then
			return nil
		end
		local x, y = intchecktbl[type(a)](a), intchecktbl[type(b)](b)
		if x == nil or y == nil then return nil end
		return (x < y and x or y)
	end
end
if type(max) ~= 'function' then
	---@param a integer
	---@param b integer
	---@return integer|nil largestNum
	---returns either `a` or `b` depending on which is larger
	local function max(a, b)
		if not (intchecktbl[type(a)] or intchecktbl[type(b)]) then
			return nil
		end
		local x, y = intchecktbl[type(a)](a), intchecktbl[type(b)](b)
		if x == nil or y == nil then return nil end
		return (x > y and x or y)
	end
end

local meth = {}
---@param cap integer The absolute value of the cap
---@param val integer
---@return integer|nil clampedOrNil
---Clamps `val` to absolute range `cap` (+/-)
function meth.absClamp(cap, val)
	if val == nil then return nil end
	return max(min(cap, val), -(cap))
end
---@param mnm integer The minimum value of the cap
---@param mxm integer The maximum value of the cap
---@param val integer
---@return integer|nil clampedOrNil
---Clamps `val` to a specific range between `mnm` and `mxm`
function meth.clamp(mnm, mxm, val)
	if val == nil then return nil end
	return max(min(mxm, val), mnm)
end
---@param mnm integer The minimum value of the cap
---@param mxm integer The maximum value of the cap
---@param val integer
---@return boolean|nil result
---Checks if `val` is in a specific range between `mnm` and `mxm`
function meth.inRange(mnm, mxm, val)
	if val == nil then return nil end
	return (val <= mxm) and (val >= mnm)
end
---@param cap integer The absolute value of the cap
---@param val integer
---@return boolean|nil result
---Checks if `val` is in a specific range between `mnm` and `mxm`
function meth.inAbsRange(cap, val)
	if val == nil then return nil end
	return (val <= cap) and (val >= -cap)
end
---@param val integer
---@return boolean result
---Checks if `val` is an integer
function meth.isInt(val)
    return not (tonumber(val) == nil)
end

local function cTrue(val)
	return (val and val ~= 0
	and val ~= '' and val ~= {})
end

local namespace = 'Math'
if type(rawget(_G, namespace)) ~= 'table' then
	rawset(_G, namespace, meth)
else
	if #Math < #meth then
		rawset(_G, namespace, meth)
	end
end