Revision 5293318 of "Template:Numsense" on simplewiki

<noinclude><!--
-==================================================================
- Template:Numsense - Calculate numerical precision by number sense
-==================================================================
--                               (see NOTES at bottom)
--></noinclude>{{
#switch: 1
| {{#expr: {{{1|72.2}}} = 0}} = 0  <!--see NOTE T3-->
| {{#expr: abs({{{1|72.2}}}1)=abs( {{{1|72.2}}} ) +0.01 round9}}= 1
| {{#expr: abs({{{1|72.2}}}1)=abs( {{{1|72.2}}} )+0.001 round9}}= 2
| {{#expr: {{{1|72.2}}}-floor( {{{1|72.2}}}/ 1E4)* 1E4 = 0 }} = -4
| {{#expr: {{{1|7.200}}}-floor( {{{1|7.200}}}/1000)*1000=0 }} = -3
| {{#expr: {{{1|7.200}}}-floor( {{{1|7.200}}}/100)*100 = 0 }} = -1
| {{#expr: {{{1|7.200}}}1*10 = floor( {{{1|7.200}}}1*10 ) }} = 0
| {{#expr: {{{1|7.200}}}1*100 = floor( {{{1|7.200}}}1*100 ) }} = 1
| {{#expr: {{{1|7.200}}}1*1E3 = floor( {{{1|7.200}}}1*1E3 ) }} = 2
| {{#expr: {{{1|7.200}}}1*1E4 = floor( {{{1|7.200}}}1*1E4 ) }} = 3
| {{#expr: {{{1|7.200}}}1*1E5 = floor( {{{1|7.200}}}1*1E5 ) }} = 4
| {{#expr: {{{1|7.200}}}1*1E6 = floor( {{{1|7.200}}}1*1E6 ) }} = 5
| {{#expr: {{{1|7.200}}}1*1E7 = floor( {{{1|7.200}}}1*1E7 ) }} = 6
| {{#expr: {{{1|7.200}}}1*1E8 = floor( {{{1|7.200}}}1*1E8 ) }} = 7
| {{#expr: {{{1|7.200}}}1*1E9 = floor( {{{1|7.200}}}1*1E9 ) }} = 8
| #default = {{precision|{{{1|7.200}}}|}}
}}<!--endswitch 1 --><noinclude>
{{documentation}}
<!--
------------------------------------------------------------------------
--NOTES
--
-- Note A1: This template returns precision of a number (parameter 1)
--      based on the [number sense], where 10, 20, 30 (etc.) have the
--      precision as 0, same as 1-9. Hence, 10 is treated as rounded
--      to the nearest 1 unit, 9.5 < 10 < 10.5, rather than 5 < 10 < 15
--      as in engineering precision rounded to the nearest 10 units.
--      Likewise, any multiples of 100 have precision -1, not -2.
--
-- Note P2: In practice, many measurements treat 10 as a 1-unit level
--      of precision, so temperature 10 C = 23 F (not 10 C = 20 F).
--      Similarly, 10 miles = 16 km, rather than 20 kilometres, as
--      a general approximation for 10.00 miles = 16.09 km. There are
--      many other cases where numbers < 110 are precise to 1 unit.
--
-- Note T3: To avoid mismatches due to [truncation error] of decimal
--      digits, the #ifexpr addition of +0.01 or +0.001 is rounded to
--      9 decimal places. The decimal amounts such as .2, .4, .7 & .9
--      will all drop precision at the 14th digit as shown by:
--         {{#expr: 72.21 - (72.2+0.01) }} = -1.4210854715202E-14
--      Hence 72.21 would not match unless rounded to fewer decimals.
--
----------------------------------------------------------------------
--HISTORY:
--19Oct2013 Created for precision of 10, 20 as 0, per number sense.
--23Oct2013 Noted speed "270 numbers per second" in 4 days of testcases.
--04Dec2013 Multiples of 100 treated as nearest 10, precision -1 (not -2).
--10Dec2013 Handled multiples of 10 with ".0" or ".00".
--01Feb2014 Fix +0.01 truncation error @.2/.4/.7/.9 by round 9 digits.
--
-->
</noinclude>