Module:MutationValue

local p = {}

local function round_half_up(n) local base, frac = math.modf(n) if frac >= 0.5 then return base + 1 else return base end end

function truncate_to(number, max_digits) local integral_part_digits = math.floor(math.log10(number)) + 1 if integral_part_digits >= max_digits then return round_half_up(number) else local digit_diff_pow10 = 10^(max_digits - integral_part_digits) return round_half_up(number * digit_diff_pow10) / digit_diff_pow10 end end

function p.main(frame) local args = require("Module:Arguments").getArgs(frame) local base = args['base'] local eqt = args['equation'] local tmp = args['cap'] local unit = args['unit'] local d = args['digits'] local vcap = args['value_cap'] if not tmp then tmp = 999999 end if not d then d = 1 end if not unit then unit = '' end if not vcap then vcap = 999999 end d = tonumber(d) cap = math.min(60, tonumber(tmp)) base = tonumber(base) result = {} result[1] = ' ' result[2] = '{| class=wikitable style="text-align:center;'	result[3] = '!Number of stats || 1 '	result[4] = '|-'	result[5] = '|Mutation effect || ' .. base .. unit .. ' '	result[6] = '|}'	result[7] = ' '	local equation = ''	local value = 0	for k = 1, math.min(9, cap-1) do		result[3] = result[3] .. '|| ' .. tostring(k+1)		equation = eqt:gsub('base', base):gsub('i', k)		value = tonumber(mw.ext.ParserFunctions.expr(equation))		value = truncate_to(value, d)		result[5] = result[5] .. '|| ' .. value .. unit	end	local k2 = 0	for k = 3, math.floor((cap-1)/5) do		k5 = k*5		result[3] = result[3] .. '|| ' .. tostring(k5)		equation = eqt:gsub('base', base):gsub('i', tostring(k5-1))		value = tonumber(mw.ext.ParserFunctions.expr(equation))		value = truncate_to(value, d)		if k5 == cap then value = math.min(value, vcap) end		result[5] = result[5] .. '|| ' .. value .. unit	end	if cap-1 > 5*math.floor((cap-1)/5) then result[3] = result[3] .. '|| ' .. tostring(cap) equation = eqt:gsub('base', base):gsub('i', tostring(cap-1)) value = tonumber(mw.ext.ParserFunctions.expr(equation)) value = truncate_to(value, d)		value = math.min(value, vcap) result[5] = result[5] .. '|| ' .. value .. unit end if cap < 60 then result[3] = result[3] .. '+ ' end result[3] = result[3] .. '|| ...'	result[5] = result[5] .. '|| ...'	return table.concat(result, "\n") end

return p