local p =
function p.factor(frame) -- Consider calling the parser function #expr -- to simplify a potential mathematical expression? number = tonumber(frame.args[1]) if number
productSymbol = frame.args['product'] or 'ยท' bold = frame.args['bold'] and true big = frame.args['big'] and true serif = frame.args['serif'] and true primeLink = frame.args['prime'] and true
number = math.floor(number) if number < 2 or number > 1000000000 or number
result = "" currentNumber = number power = 0 divisor = 2
-- Attempt factoring by the value of the divisor -- divisor increments by 2, except first iteration (2 to 3) while divisor <= math.sqrt(currentNumber) do power = 0 while currentNumber % divisor
-- Concat result and increment divisor -- when divisor is 2, go to 3. All other times, add 2 result = result .. powerformat(divisor, power, productSymbol) divisor = divisor + (divisor
if currentNumber ~= 1 then result = result .. currentNumber .. ' ' .. productSymbol .. ' ' end
if currentNumber
result = string.sub(result,1,-4)
return format(result)end
function powerformat(divisor, power, productSymbol) if power < 1 then return elseif power
function format(numString) if bold then numString = ''..numString..'' end
ret = (serif or big) and '
' or ) .. numString .. ((serif or big) and '' or )return retend
return p