local BASE = Arguments[1]
local SCALE = Arguments[2]
local MIN = Arguments[3]
local MAX = Arguments[4]
local INCREMENT = Arguments[5]
local PRECISION = Arguments[6]

math.round = function(value, places)
	local mult = 10 ^ (places or 0)
	
    return math.floor(value * mult + 0.5) / mult
end

function _is_valid(value)
	return value >= MIN and value <= MAX
end

function format_value(value)
	return math.round(value, PRECISION)
end

function convert_to_display_value(value)
	return format_value(BASE + (value / SCALE))
end

function convert_to_raw_value(value)
	return math.tointeger(math.round((value * SCALE) - BASE))
end

function increase_value(value)
	local incValue = (value + INCREMENT)

	if not _is_valid(incValue) then
		incValue = math.min(MAX, math.max(MIN, value))
	end
	
	return incValue
end

function decrease_value(value)
	local decValue = (value - INCREMENT)

	if not _is_valid(decValue) then
		decValue = math.max(MIN, math.min(MAX, value))
	end
	
	return decValue
end