Module:Rational: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 746: | Line 746: | ||
end | end | ||
-- FJS representation of a rational number | |||
-- might be a bit incorrect | |||
function p.as_FJS(a) | function p.as_FJS(a) | ||
if type(a) == 'number' then | if type(a) == 'number' then | ||
Line 774: | Line 776: | ||
table.sort(utonal) | table.sort(utonal) | ||
local fifths = b[3] or 0 | local fifths = b[3] or 0 | ||
if fifths % 7 == 6 then | |||
b = p.div(b, red(p.new(2, 3))) | |||
else | |||
b = p.div(b, red(p.pow(p.new(3, 2), fifths % 7))) | |||
end | |||
b = p.div(b, p.pow(p.new(2187, 2048), math.floor((fifths + 1) / 7))) | |||
local octaves = b[2] or 0 | local octaves = b[2] or 0 | ||
local noshift = {1, 5, 2, 6, 3, 7, 4} | local noshift = {1, 5, 2, 6, 3, 7, 4} | ||
local | local base_num = noshift[1 + (fifths % 7)] | ||
local num = base_num + octaves * 7 | |||
if octaves < 0 then | if octaves < 0 then | ||
fifths = -fifths | fifths = -fifths | ||
-- | octaves = -octaves - 1 | ||
base_num = (8 - base_num) % 7 + 1 | |||
num = -base_num - octaves * 7 | |||
end | end | ||