Module:Rational: Difference between revisions

Plumtree (talk | contribs)
m as_FJS() changed
Plumtree (talk | contribs)
mNo edit summary
Line 1,320: Line 1,320:
-- return a rational number in ket notation
-- return a rational number in ket notation
-- NaN, infinity, zero values use special representations
-- NaN, infinity, zero values use special representations
function p.as_ket(a, frame)
function p.as_ket(a, frame, skip_many_zeros, only_numbers)
skip_many_zeros = skip_many_zeros or true
only_numbers = only_numbers or false
if type(a) == 'number' then
if type(a) == 'number' then
a = p.new(a)
a = p.new(a)
Line 1,343: Line 1,345:
local s = ''
local s = ''
if a.sign < 0 then
if not only_numbers and a.sign < 0 then
s = s .. '-'
s = s .. '-'
end
end
Line 1,359: Line 1,361:
if (a[i] or 0) ~= 0 then
if (a[i] or 0) ~= 0 then
if zeros_n >= 4 then
if skip_many_zeros and zeros_n >= 4 then
template_arg = template_arg_without_trailing_zeros
template_arg = template_arg_without_trailing_zeros
if #template_arg > 0 then
if #template_arg > 0 then
Line 1,376: Line 1,378:
template_arg = '0'
template_arg = '0'
end
end
s = s .. frame:expandTemplate{
if only_numbers then
title = 'Monzo',
s = s .. template_arg
args = {template_arg}
else
}
s = s .. frame:expandTemplate{
title = 'Monzo',
args = {template_arg}
}
end
return s
return s
end
end