Module:Rational: Difference between revisions

m Oops
Ganaram inukshuk (talk | contribs)
Add int limit function (prepwork for a separate algorithm)
Line 887: Line 887:
end
end
return max_factor
return max_factor
end
-- Find integer limit of a ratio
-- For a ratio p/q, this is simply max(p, q)
function p.int_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)
local num, den = p.as_pair(a_copy)
return math.max(num, den)
end
end