Module:Rational: Difference between revisions

Plumtree (talk | contribs)
m A few norms implemented
Plumtree (talk | contribs)
m cents() implemented
Line 733: Line 733:
end
end
return n_factors <= 1 and m_factors <= 1
return n_factors <= 1 and m_factors <= 1
end
-- convert a rational number to cents
function p.cents(a)
if type(a) == 'number' then
a = p.new(a)
end
if a.nan or a.inf or a.zero then
return nil
end
if a.sign < 0 then
return nil
end
local c = 0
for factor, power in pairs(a) do
if type(factor) == 'number' then
c = c + power * math.log(factor)
end
end
return c * 1200 / math.log(2)
end
end