Module:Rational: Difference between revisions
Since a cent is just a scaled octave, the two functions should behave the same |
Added odd-limit function, as recommended by fredg999 |
||
Line 895: | Line 895: | ||
end | end | ||
return max_factor | return max_factor | ||
end | |||
-- Find odd limit of a ratio | |||
-- For a ratio p/q, this is simply max(p, q) where powers of 2 are ignored | |||
function p.odd_limit(a) | |||
if type(a) == 'number' then | |||
a = p.new(a) | |||
end | |||
if a.nan or a.inf or a.zero then | |||
return nil | |||
end | |||
local a_copy = p.copy(a) | |||
if a_copy[2] ~= nil then | |||
a_copy[2] = 0 | |||
end | |||
local num, den = p.as_pair(a_copy) | |||
return math.max(num, den) | |||
end | end | ||