Module:Rational: Difference between revisions
Add int limit function (prepwork for a separate algorithm) |
added is_within_int_limit function, because there were enough use-cases to add it |
||
Line 869: | Line 869: | ||
end | end | ||
-- | -- Check if ratio is within an int limit; that is, neither its numerator nor | ||
-- | -- denominator exceed that limit. | ||
function p. | function p.is_within_int_limit(a, lim) | ||
return p.int_limit(a) <= lim | |||
end | end | ||
Line 918: | Line 904: | ||
local num, den = p.as_pair(a_copy) | local num, den = p.as_pair(a_copy) | ||
return math.max(num, den) | return math.max(num, den) | ||
end | |||
-- find max prime involved in the factorisation | |||
-- (a.k.a. prime limit or harmonic class) of a rational number | |||
function p.max_prime(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 max_factor = 0 | |||
for factor, _ in pairs(a) do | |||
if type(factor) == "number" then | |||
if factor > max_factor then | |||
max_factor = factor | |||
end | |||
end | |||
end | |||
return max_factor | |||
end | end | ||