Module:Rational: Difference between revisions

Ganaram inukshuk (talk | contribs)
Add int limit function (prepwork for a separate algorithm)
Ganaram inukshuk (talk | contribs)
added is_within_int_limit function, because there were enough use-cases to add it
Line 869: Line 869:
end
end


-- find max prime involved in the factorisation
-- Check if ratio is within an int limit; that is, neither its numerator nor
-- (a.k.a. prime limit or harmonic class) of a rational number
-- denominator exceed that limit.
function p.max_prime(a)
function p.is_within_int_limit(a, lim)
if type(a) == "number" then
return p.int_limit(a) <= lim
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


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