Module:Rational: Difference between revisions

Plumtree (talk | contribs)
mNo edit summary
Plumtree (talk | contribs)
mNo edit summary
Line 441: Line 441:
end
end
return true
return true
end
-- determine whether a rational number lies within [1; equave)
function p.is_reduced(a, equave, large)
equave = equave or 2
if type(a) == 'number' then
a = p.new(a)
end
if a.nan or a.inf or a.zero or a.sign < 0 then
return false
end
if large then
-- an approximation
local cents = p.cents(a)
local cents_max = p.cents(equave)
return cents >= 0 and cents < cents_max
else
return p.geq(a, 1) and p.lt(a, equave)
end
end
end


Line 461: Line 480:
end
end
if reduced then
if reduced then
if large then
return p.reduced(a, 2, large)
-- an approximation
local cents = p.cents(a)
if cents < 0 or cents >= 1200 then
return false
end
else
if p.lt(a, 1) or p.geq(a, 2) then
return false
end
end
end
end
return true
return true
Line 477: Line 486:


-- determine whether a rational number represents a subharmonic
-- determine whether a rational number represents a subharmonic
function p.is_subharmonic(a, reduced)
function p.is_subharmonic(a, reduced, large)
if type(a) == 'number' then
if type(a) == 'number' then
a = p.new(a)
a = p.new(a)
Line 494: Line 503:
end
end
if reduced then
if reduced then
if p.lt(a, 1) or p.geq(a, 2) then
return p.reduced(a, 2, large)
return false
end
end
end
return true
return true