Module:Rational: Difference between revisions

Plumtree (talk | contribs)
Ket notation added
Plumtree (talk | contribs)
Comparisons implemented
Line 153: Line 153:
function p.sub(a, b)
function p.sub(a, b)
return p.add(a, p.mul(b, -1))
return p.add(a, p.mul(b, -1))
end
-- determine whether a rational number is less than another; integers are also allowed
function p.lt(a, b)
local c = p.sub(a, b)
if c.zero then
return false
else
return c.sign == -1
end
end
-- determine whether a rational number is less or equal to the other; integers are also allowed
function p.leq(a, b)
local c = p.sub(a, b)
if c.zero then
return true
else
return c.sign == -1
end
end
-- determine whether a rational number is greater than another; integers are also allowed
function p.gt(a, b)
local c = p.sub(a, b)
if c.zero then
return false
else
return c.sign == 1
end
end
-- determine whether a rational number is greater or equal to the other; integers are also allowed
function p.geq(a, b)
local c = p.sub(a, b)
if c.zero then
return true
else
return c.sign == 1
end
end
-- determine whether a rational number is equal to another; integers are also allowed
function p.eq(a, b)
local c = p.sub(a, b)
return c.zero
end
end