starlit  Diff

Differences From Artifact [28fc5b216f]:

To Artifact [988785061c]:


    22     22   	return dsq / (dist^2)
    23     23   	-- [0,1) == less then
    24     24   	-- 1 == equal
    25     25   	-- >1 == greater than
    26     26   end
    27     27   
    28     28   -- produce an SI expression for a quantity
    29         -fn.si = function(unit, val, full, uncommonScales)
           29  +fn.si = function(unit, val, full, uncommonScales, prec)
    30     30   	if val == 0 then return '0 ' .. unit end
    31     31   	local scales = {
    32     32   		{30, 'Q', 'quetta',true,  'q', 'quecto',true};
    33     33   		{27, 'R', 'ronna', true,  'r', 'ronto', true};
    34     34   		{24, 'Y', 'yotta', true,  'y', 'yocto', true};
    35     35   		{21, 'Z', 'zetta', true,  'z', 'zepto', true};
    36     36   		{18, 'E', 'exa',   true,  'a', 'atto',  true};
................................................................................
    45     45   	for i, s in ipairs(scales) do
    46     46   		local amt, smaj, pmaj, cmaj,
    47     47   		           smin, pmin, cmin = lib.tbl.unpack(s)
    48     48   
    49     49   		if math.abs(val) > 1 then
    50     50   			if uncommonScales or cmaj then
    51     51   				local denom = 10^amt
           52  +				local vd = val/denom
           53  +				if prec then vd = lib.math.trim(vd, prec) end
    52     54   				if math.abs(val) >= (10^(amt)) then
    53     55   					return string.format("%s %s%s",
    54         -						val / denom, (full and pmaj or smaj), unit)
           56  +						vd, (full and pmaj or smaj), unit)
    55     57   				end
    56     58   			end
    57     59   		elseif math.abs(val) < 1 then
    58     60   			if uncommonScales or cmin then
    59     61   				local denom = 10^-amt
           62  +				local vd = val/denom
           63  +				if prec then vd = lib.math.trim(vd, prec) end
    60     64   				if math.abs(val) <= (10^-(amt-1)) then
    61     65   					return string.format("%s %s%s",
    62         -						val / denom, (full and pmin or smin), unit)
           66  +						vd, (full and pmin or smin), unit)
    63     67   				end
    64     68   			end
    65     69   		end
    66     70   	end
    67     71   
    68     72   	return string.format("%s %s", val, unit)
    69     73   end