Module:Rational: Difference between revisions
mNo edit summary |
m subgroup() implemented |
||
Line 780: | Line 780: | ||
s = s .. '<sup>' .. a[factor] .. '</sup>' | s = s .. '<sup>' .. a[factor] .. '</sup>' | ||
end | end | ||
end | |||
return s | |||
end | |||
-- return the subgroup generated by primes from a rational number's prime factorisation | |||
function p.subgroup(a) | |||
if type(a) == 'number' then | |||
a = p.new(a) | |||
end | |||
if a.nan or a.inf or a.zero then | |||
return 'n/a' | |||
end | |||
local s = '' | |||
local factors = {} | |||
for factor, power in pairs(a) do | |||
if type(factor) == 'number' then | |||
table.insert(factors, factor) | |||
end | |||
end | |||
table.sort(factors) | |||
for i, factor in ipairs(factors) do | |||
if i > 1 then s = s .. '.' end | |||
s = s .. factor | |||
end | end | ||
return s | return s |