— happened again, typed answer, accidentally hit a link, answer gone … is it possible to have a fallback as in bugs? —
@djohn49: like such ideas,
@Lupp: “standard rules”? if calc would consider:
- ‘addition, sum, difference, mod, round results have max as many decimals as the max in the operands’ and
- ‘multiplication result has max as many as the amounts in the factors added’ and
- ‘other operations have 16 significant decimal digits while their 53-bit-dyadic-ULP is smaller than their 16-digit-decimal-ULP, else 15’ and
- ‘round value! to that pattern, not only display’ and
- allow the user to see all! digits, and
- if displaying less digits than available in value mark it in display,
would make calc a better program, users keep calm, and this world a better one,
@djohn49:
some time ago i cluttered together a macro trying to calculate the amount of ‘valuable digits’ (possibly valuable digits) in a figure, it suffers from multiple shortcomings (idiosyncratic rounding and rounding fails in calc, differences between ‘sheet’ and ‘basic’, … ) but at least ‘does something’, perhaps you can use and / or improve it?
@Lupp: - or others -
if you like to have a look in it and tell me where i can do better … highly appreciated!
function decimals_s(ByVal darg1 as double) 'inputs: "+/-", "xy", "xy0", "x,y", "0x,y0", "xE+/-n", "x,yE+/-n", "x,y00E+/-n"?, "x,y00hE+/-n", ...
'bs: 2020-11-16 - beware !!! under work !!! 'round' has fails, e-strings sometimes contain 'hidden value'
'evaluate different value representations about amount of decimal digits, gives max digits which may! contain valuable content,
'2021-03-10: added handling of '0',
'2020-11-28: new attempt with generalised handling of hidden value,
'2020-11-21: continue checking, compare versions,
if darg1 = 0 then
decimals_s = -307
else
if darg1 < 0 then darg1 = -darg1 'negative values, solved?
if (instr(1,darg1,"E") > 0) then 'scientific notation
e_num = - val(right(darg1,(len(darg1)-instr(1,darg1,"E")))) 'cInt had problems with "+" sign,
if darg1 <> val(left(darg1, instr(1,darg1,"E")-1)) * 10^-e_num then
e_num = e_num + 2
endif
str_part = left(darg1,instr(1,darg1,"E")-1)
str_dec = len(trim(str(str_part))) - 1
if instr(1,str(str_part),"-") then '"-" is not a decimal place
str_dec = str_dec - 1
endif
if instr(1,trim(str(str_part)),".") then '"." doesn't count as digit
str_dec = str_dec - 1
endif
decimals_s = e_num + str_dec
else
decimals_s = decimals_std_s(darg1)
endif
endif
end function 'decimals_s
function decimals_std_s(ByVal darg1 as double)
'bs: 2020-11-21
'calculate amount of decimal digits in 'standard' strings,
'2021-03-10: added handling of '0',
'they don't 'hide content'? - they do :-(
'or if the do they are exchanged as e-strings ... i hope, have to check ... it depends :-(
if darg1 = 0 then
decimals_s = -307
else
if (instr(1,darg1,"E") > 0) then 'scientific notation
decimals_std_s = "fail, scientific notation"
else
if darg1 < 0 then
darg1 = -darg1 'negative values, solved?
endif
dtemp1 = darg1 * 1e14
dtemp2 = int(darg1 * 1e14)
dtemp3 = darg1 * 1e15
dtemp4 = int(darg1 * 1e15)
dtemp5 = darg1 * 1e16
dtemp6 = int(darg1 * 1e16)
if darg1 * 1e14 <> int(darg1 * 1e14) then
if darg1 * 1e15 <> int(darg1 * 1e15) then
if darg1 * 1e16 <> int(darg1 * 1e16) then
decimals_std_s = 17
else
decimals_std_s = 16
endif
else
decimals_std_s = 15
endif
else
if instr(1,str(darg1),".") then 'decimal number
decimals_std_s = len(trim(str(darg1))) - instr(1,trim(str(darg1)),".") + itemp1
else 'integer string
decimals_std_s = 0
do while right(darg1, 1) = "0"
decimals_std_s = decimals_std_s - 1
darg1 = left(darg1, len(trim(str(darg1))) - 1)
loop
endif
endif
endif
endif
end function 'decimals_std_s