Module:Rational: Difference between revisions

Plumtree (talk | contribs)
m is_highly_composite(): basic implementation
Plumtree (talk | contribs)
m eq() optimisation
Line 305: Line 305:
-- determine whether a rational number is equal to another; integers are also allowed
-- determine whether a rational number is equal to another; integers are also allowed
function p.eq(a, b)
function p.eq(a, b)
local c = p.sub(a, b)
if type(a) == 'number' then
return c.zero
a = p.new(a)
end
if type(b) == 'number' then
b = p.new(b)
end
if a.nan or b.nan then
return false
end
if a.inf and b.inf then
return a.sign == b.sign
end
if a.inf or b.inf then
return false
end
if a.zero and b.zero then
return true
end
if a.zero or b.zero then
return false
end
for factor, power in pairs(a) do
if b[factor] ~= power then
return false
end
end
return true
end
end