Module:Rational: Difference between revisions

Plumtree (talk | contribs)
m Partial FJS implementation
Plumtree (talk | contribs)
m A bit more of FJS implemented
Line 664: Line 664:
if type(a) == 'number' then
if type(a) == 'number' then
a = p.new(a)
a = p.new(a)
end
if a.nan or a.inf or a.zero then
return nil
end
end
local b = p.copy(a)
local b = p.copy(a)
Line 709: Line 712:
local fifth_shift = FJS_master(prime)
local fifth_shift = FJS_master(prime)
return reb(p.div(prime, p.pow(3, fifth_shift)))
return reb(p.div(prime, p.pow(3, fifth_shift)))
end
function p.as_FJS(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 b = p.copy(a)
local otonal = {}
local utonal = {}
for factor, power in pairs(a) do
if type(factor) == 'number' and factor > 3 then
local comma = formal_comma(factor)
b = p.div(b, p.pow(comma, power))
if power > 0 then
for i = 1, power do
table.insert(otonal, factor)
end
else
for i = 1, -power do
table.insert(utonal, factor)
end
end
end
end
local fifths = b[3] or 0
b = p.div(b, p.pow(p.new(3, 2), fifths))
local octaves = b[2] or 0
mw.log(fifths, octaves, table.concat(otonal), table.concat(utonal))
-- TODO: finish the implementation
end
end