https://heald.nga.gov/mediawiki/index.php?title=Template:Precision&feed=atom&action=historyTemplate:Precision - Revision history2024-03-28T20:14:21ZRevision history for this page on the wikiMediaWiki 1.35.2https://heald.nga.gov/mediawiki/index.php?title=Template:Precision&diff=2757&oldid=prevEmily Pugh: 1 revision2013-09-10T20:39:15Z<p>1 revision</p>
<p><b>New page</b></p><div><includeonly>{{#invoke:Math|precision|{{{1|0}}}|check_fraction=true}}</includeonly><noinclude><br />
{{documentation}}<br />
</noinclude></div>Emily Pughhttps://heald.nga.gov/mediawiki/index.php?title=Template:Precision&diff=1131&oldid=prevEmily Pugh: 1 revision2012-04-18T17:27:25Z<p>1 revision</p>
<p><b>New page</b></p><div><noinclude><!--<br />
--============================================================<br />
-- Getprecision - Count decimal digits or in fraction (2+1/3)<br />
--============================================================<br />
-- (see NOTES at bottom)<br />
--></noinclude>{{<br />
#expr: ( 0 {{<br />
#ifexpr: {{{1|0.0000}}}0={{{1|0.0000}}} |<!--see NOTE Z7--><br />
-1 + <noinclude><!--see NOTE S5--></noinclude><br />
{{#switch: x{{{1|0.0000}}}<br />
|{{padleft:|6|x{{{1}}}}}=5<br />
|{{padleft:|5|x{{{1}}}}}=4<br />
|{{padleft:|7|x{{{1|0.0000}}}}}=6<br />
|{{padleft:|4|x{{{1}}}}}=3<br />
|{{padleft:|8|x{{{1}}}}}=7<br />
|{{padleft:|9|x{{{1}}}}}=8<br />
|{{padleft:|10|x{{{1}}}}}=9<br />
|{{padleft:|11|x{{{1}}}}}=10<br />
|{{padleft:|2|x{{{1}}}}}=1 <!--for "0"--><br />
|{{padleft:|12|x{{{1}}}}}=11<br />
|{{padleft:|13|x{{{1}}}}}=12<br />
|{{padleft:|14|x{{{1}}}}}=13<br />
|{{padleft:|15|x{{{1}}}}}=14<br />
|{{padleft:|16|x{{{1}}}}}=15<br />
|{{padleft:|17|x{{{1}}}}}=16<br />
|{{padleft:|18|x{{{1}}}}}=17<br />
|{{padleft:|19|x{{{1}}}}}=18<br />
|{{padleft:|20|x{{{1}}}}}=19<br />
|{{padleft:|21|x{{{1}}}}}=20<br />
|{{padleft:|3|x{{{1}}}}}=2<br />
|{{padleft:|22|x{{{1}}}}}=21<br />
|{{padleft:|23|x{{{1}}}}}=22<br />
|{{padleft:|24|x{{{1}}}}}=23<br />
|{{padleft:|25|x{{{1}}}}}=24<br />
|{{padleft:|26|x{{{1}}}}}=25<br />
|{{padleft:|27|x{{{1}}}}}=26<br />
|{{padleft:|28|x{{{1}}}}}=27<br />
|{{padleft:|29|x{{{1}}}}}=28<br />
|{{padleft:|30|x{{{1}}}}}=29<br />
|{{padleft:|31|x{{{1}}}}}=30<br />
|{{padleft:|32|x{{{1}}}}}=31<br />
|{{padleft:|33|x{{{1}}}}}=32<br />
|{{padleft:|34|x{{{1}}}}}=33<br />
|{{padleft:|35|x{{{1}}}}}=34<br />
|{{padleft:|36|x{{{1}}}}}=35<br />
|{{padleft:|37|x{{{1}}}}}=36<br />
|{{padleft:|38|x{{{1}}}}}=37<br />
|{{padleft:|39|x{{{1}}}}}=38<br />
|{{padleft:|40|x{{{1}}}}}=39<br />
|{{padleft:|41|x{{{1}}}}}=40<br />
|#default = 41<br />
}} - floor(<br />
ln (floor( abs({{{1|0}}}) )+0.99 )/ln10 ) - 1<br />
{{#ifexpr: floor(abs({{{1|0}}}) )=0 |-1}}<br />
{{#ifeq: {{{1|0.0000}}}x|0x| + 1}}{{<br />
#ifexpr: {{{1|500}}}<0| - 1}}<!--For minus sign--><br />
|<noinclude><!--else for integers--></noinclude>{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/10)*10|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/100)*100|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/1E3)*1E3|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/1E4)*1E4|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/1E5)*1E5|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/1E6)*1E6|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/1E7)*1E7|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/1E8)*1E8|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/1E9)*1E9|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/1E10)*1E10|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/1E11)*1E11|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/1E12)*1E12|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/1E13)*1E13|-1}}{{<br />
#ifexpr:{{{1|500}}}=floor({{{1|500}}}/1E14)*1E14|-1<br />
}}}}<noinclude><!--endif {1}0={1}<br />
--------------------------------------------------------<br />
Check for fraction "/" to use logn of denominator, by<br />
clearing prior count: (..prior..)*0 + (logn denom / logn 10).<br />
(see NOTE A1). The whole expression ends with close ")".<br />
--></noinclude>{{<br />
#if: {{#titleparts:{{{1|6+3~8}}}|1|2}}| )*0 + (<br />
(ln {{#titleparts:{{{1|6+3/8}}}|1|2}} / ln10)<br />
}}<noinclude><!--endif fraction<br />
--></noinclude> ) }}<noinclude><!--endexpr# (close paren.)<br />
--<br />
--------------------------------------------------------------<br />
--NOTES:<br />
-- [ These comments are skipped by <noinclude> and not send<br />
-- inside formatted Internet pages, only during edit. ]<br />
--<br />
--NOTE A1: This template determines the precision of decimals<br />
-- by counting the length of the numeric string (in a<br />
-- #switch comparing lengths of padded strings), then<br />
-- subtracting integer length, minus the decimal point,<br />
-- and minus 1 if negative. For integers, 1 place is<br />
-- subtracted for each trailing 0 on the integer.<br />
-- For fractions, any prior count is cleared x 0, then<br />
-- size is logarithm of denominator divided by logn 10:<br />
-- (..prior...)*0 + floor(logn denom / logn 10 - .01) + 1.<br />
--<br />
--NOTE D2: The check, for whole integers, compares the amount<br />
-- versus appending "0" at the end: when the amount is a<br />
-- decimal, then the value is unchanged by appending 0 at<br />
-- the end: so 5.23 = 5.230 is true, whereas for whole<br />
-- integers, it would be: 5 = 50 as false, due to values<br />
-- becoming n*10 for integer n. So, for integer n, the<br />
-- check rejects: n = n0 as false; hence n is integer.<br />
--<br />
--NOTE M3: The magnitude of the integer portion is calculated<br />
-- by logarithm of the floor of absolute value (divided by<br />
-- [[natural logarithm]] of 10 to adjust for e=2.71828*),<br />
-- as: ln (floor( abs({{{1|-0.050067}}}) )+0.99 )/ln10<br />
-- Function floor(x) trims the decimal part, to leave the<br />
-- whole count: 0-9 yield 0, 10-19 as 1, 1000-1999 as 3.<br />
-- The abs(x) avoids floor of negatives, floor(-0.1)= -1,<br />
-- hence using abs(x) ensures -0.1 floors to 0 not -1.<br />
-- Near zero, the +0.99 avoids invalid log of 0, but does<br />
-- not round-up any decimals, already floored as nnn.00.<br />
-- Complexity is 6 operations: floor of abs( {1} ) +0.99<br />
-- then logn div logn10, then floor that logarithm ratio.<br />
-- Decimals -1 < x < 1 yield -1, avoiding log 0.001 = -3.<br />
--<br />
--NOTE N4: Nesting of if-else and nested templates is kept to<br />
-- a minimum, due to the MediaWiki 1.6 limit of 40 levels<br />
-- of if-logic for all nested templates used together.<br />
-- Template {ordomag} was omitted to avoid 2 more levels<br />
-- of nested templates. Template {Precision} had 8 levels,<br />
-- and this template was trimmed to only 5 levels.<br />
--<br />
--NOTE S5: The #switch is run with "x" prepended in front of<br />
-- the amount, otherwise a #switch will compare as numeric<br />
-- where 2 would match "2.0" even though "2" is length 1.<br />
-- So "x2" won't match "x2.0" in non-numeric comparison.<br />
-- The #switch will exit on the first match, so smaller<br />
-- lengths are compared first, to avoid extra comparisons<br />
-- for more rare, longer numeric strings up to 41 long.<br />
--<br />
--NOTE W6: The check for integers with whole end-zeroes uses<br />
-- typical n=n/10*10, for each power of 10, where whole<br />
-- millions match: {{#ifexpr: {1}=floor( {1}/1E6 )*1E6| }}<br />
-- Previously, {Precision} had tried to use "round" to<br />
-- detect end-zeroes but "round" loses precision at -5,<br />
-- so, n00000 round -5 differs from n00000 slightly, and<br />
-- comparisons to exact rounded amounts failed to match<br />
-- some numbers when 6 or more zeroes "n000000".<br />
--<br />
--NOTE Z7: The check on zero for any .00000 compares adding 1<br />
-- to the amount, versus appending "1" at the end: if the<br />
-- amount is a decimal, then adding 1 will be larger than<br />
-- appending 1 at the end: 0.00 + 1 > 0.001, whereas for<br />
-- whole zero, it would be: 0+1 > 01 as false, due to the<br />
-- value being the same. So, for integer 0, the check<br />
-- rejects: 0+1 > 01 as false; hence whole 0 is integer.<br />
--<br />
-- WARNING: *** DO NOT DELETE COMMENTS FROM THIS TEMPLATE ***<br />
-- Unless these comments are readily available, people<br />
-- might tinker with the coding (or rename templates),<br />
-- in hopes to clarify operation because these comments<br />
-- were not nearby to explain the issues. Having these<br />
-- comments only on a doc-page increases the danger of<br />
-- explanations no longer matching the current coding.<br />
-- UPDATE these comments to match changes to the template.<br />
-- UPDATE the HISTORY during major changes (not typos).<br />
--<br />
--------------------------------------------------------------<br />
--HISTORY:<br />
--15Aug10 Created to get precision even if large or negative.<br />
--15Aug10 Put NOTES comments to explain template coding.<br />
--15Aug10 Put HISTORY comments to log major changes.<br />
--18Aug10 Fixed to handle zero: 0 as 0, 0.000 as 3, etc.<br />
--04Sep10 Fixed to handle decimals between 0~1 (by round 0).<br />
--04Sep10 Updated NOTES to explain the check appending 0 or 1.<br />
--03Jan11 Fix integer end-zeroes: 50 as -1, 500 as -2, 5000 -3.<br />
--03Jan11 Omit {Order of Magnitude} for 2 levels less nesting.<br />
--03Jan11 Omit {Str_len} for 8 fewer levels of 40-nest limit.<br />
--03Jan11 Put "noinclude" around all inter-line HTML comments.<br />
--03Jan11 Allow fraction "/": floor(ln denom/ln 10 -.01)+1.<br />
--08Feb11 Fixed to not count minus sign on negative integers.<br />
--08Feb11 Extended to handle integers with 14 end-zeroes "0".<br />
--08Feb11 Ordered length-search by most-likely (rarely 1 or 2).<br />
--10Feb11 Re-added NOTES/HISTORY to explain logic & changes.<br />
--22Jun11 Move to Precision: no need to keep all three.<br />
--22Jun11 No rounding up for fractions (i.e. ln denom/ln 10)<br />
--<br />
-->{{documentation}}</noinclude></div>Emily Pugh