Template talk:Precision

From WikiAlpha
Jump to: navigation, search

Previous Contributors

(cur | prev) 12:38, 25 March 2017‎ Jo-Jo Eumerus (talk | contribs)‎ m . . (125 bytes) (0)‎ . . (Changed protection level for "Template:Precision": Allowing template editors on some templates with full protection dating back to pre-TPROT times which aren't too often or too sensitively used. ([Edit=Require template editor access] (...) (thank)
(cur | prev) 17:12, 25 February 2013‎ Dragons flight (talk | contribs)‎ . . (125 bytes) (-134)‎ . . (Fraction case moved into Lua) (thank)
(cur | prev) 23:02, 22 February 2013‎ Dragons flight (talk | contribs)‎ . . (259 bytes) (-8,348)‎ . . (update to Lua, including handling the fractions case) (thank)
(cur | prev) 17:18, 22 June 2011‎ Jimp (talk | contribs)‎ . . (8,607 bytes) (+113)‎ . . (move & fracs history note) (thank)
(cur | prev) 15:32, 22 June 2011‎ Jimp (talk | contribs)‎ . . (8,494 bytes) (-15)‎ . . (We don't want to round up to the nearest integer in the case of fractions but instead we want the true figure (round up after if you must).) (thank)
(cur | prev) 05:18, 22 June 2011‎ Jimp (talk | contribs)‎ m . . (8,509 bytes) (0)‎ . . (moved Template:Getprecision to Template:Precision: this is the best of the three, history merge)
(cur | prev) 05:13, 22 June 2011‎ Jimp (talk | contribs)‎ m . . (136 bytes) (-8,373)‎ . . (moved Template:Precision/+ to Template:Precision: merging three versions see talk) (thank)
(cur | prev) 04:31, 12 February 2011‎ Plastikspork (talk | contribs)‎ . . (8,509 bytes) (+5,739)‎ . . (Add comments per request) (thank)
(cur | prev) 16:54, 8 February 2011‎ MSGJ (talk | contribs)‎ . . (2,770 bytes) (-5,307)‎ . . (fix for negative powers of ten, per request) (thank)
(cur | prev) 03:04, 4 January 2011‎ Dabomb87 (talk | contribs)‎ . . (8,077 bytes) (+5,644)‎ . . (per talk-page request) (thank)
(cur | prev) 13:05, 11 October 2010‎ Rich Farmbrough (talk | contribs)‎ m . . (2,433 bytes) (+11)‎ . . (update template name)
(cur | prev) 12:28, 11 October 2010‎ Stemonitis (talk | contribs)‎ . . (122 bytes) (-1)‎ . . (typo?) (thank)
(cur | prev) 12:19, 11 October 2010‎ Rich Farmbrough (talk | contribs)‎ . . (123 bytes) (+5)‎ . . (thank)

(cur | prev) 19:11, 4 October 2010‎ WOSlinker (talk | contribs)‎ . . (118 bytes) (-2,304)‎ . . (remove since included in
[edit] [purge] Template documentation

{{#invoke:Message box|tmbox}}


The Template:Precision determines the precision (as a count of decimal digits) for any amount, large or negative, using a fast algorithm. It can also handle a trailing decimal point (such as "15." or "-41.") or trailing zeroes (such as "15.34000" having precision as 5 decimal digits). For fractional input it returns the base ten logarithm of the numerator.

Examples

{{Precision|1111.123456789}} 9
{{Precision|1111.12345678}} 8
{{Precision|1111.1234567}} 7
{{Precision|1111.123456}} 6
{{Precision|1111.12345}} 5
{{Precision|1111111111.12345678}} 8
{{Precision|1111111111.1234567}} 7
{{Precision|1111111111.123456}} 6
{{Precision|1111111111.12345}} 5
{{Precision|1111111111.1234}} 4
{{Precision|1111111111.123}} 3
{{Precision|1111111111.12}} 2
{{Precision|1111111111.1}} 1
{{Precision|1111111111.10}} 2
{{Precision|1111111111.100}} 3
{{Precision|1111111111.1000}} 4
{{Precision|1111111111.10000}} 5
{{Precision|1111111111}} 0
{{Precision|1111111110}} -1
{{Precision|1111111100}} -2
{{Precision|1111111000}} -3
{{Precision|1111110000}} -4
{{Precision|1111100000}} -5
{{Precision|1111000000}} -6
{{Precision|1110000000}} -7
{{Precision|1100000000}} -8
{{Precision|0}} 0
{{Precision|1}} 0
{{Precision|22.45}} 2
{{Precision|22.12345}} 5
{{Precision|22}} 0
{{Precision|22000}} -3
{{Precision|-15.275}} 3
{{Precision|-15.2500}} 4
{{Precision|23000222000111.432}} 3
{{Precision|-15.123}} 3
{{Precision|0.09}} 2
{{Precision|0.88}} 2
{{Precision|880000}} -4
{{Precision|90000000}} -7

Known bugs

  • For numbers in scientific notation, the precision is typically returned as too low by 1 decimal place. Example: {{precision |7.1234E+06}} → -2 (should be precision as 4 decimal digits, not 3).

Technical notes

  • NOTE A1: This template determines the precision of decimals by counting the length of the numeric string (in a #switch comparing lengths of padded strings), then subtracting integer length, minus the decimal point, and minus 1 if negative. For integers, 1 place is subtracted for each trailing 0 on the integer. For fractions, any prior count is cleared x 0, then returns the base ten logarithm of denominator: (..prior...)*0 + (ln denom / ln 10).
  • NOTE D2: The check, for whole integers, compares the amount versus appending "0" at the end: when the amount is a decimal, then the value is unchanged by appending 0 at the end: so 5.23 = 5.230 is true, whereas for whole integers, it would be: 5 = 50 as false, due to values becoming n*10 for integer n. So, for integer n, the check rejects: n = n0 as false; hence n is integer.
  • NOTE M3: The magnitude of the integer portion is calculated by logarithm of the floor of absolute value (divided by natural logarithm of 10 to adjust for e=2.71828*), as: ln (floor( abs(-0.050067) )+0.99 )/ln10 Function floor(x) trims the decimal part, to leave the whole count: 0-9 yield 0, 10-19 as 1, 1000-1999 as 3. The abs(x) avoids floor of negatives, floor(-0.1)= -1, hence using abs(x) ensures -0.1 floors to 0 not -1. Near zero, the +0.99 avoids invalid log of 0, but does not round-up any decimals, already floored as nnn.00. Complexity is 6 operations: floor of abs( {1} ) +0.99 then log10x (lnx ÷ ln10), then floor that logarithm ratio. Decimals -1 < x < 1 yield -1, avoiding log 0.001 = -3.
  • NOTE N4: Nesting of if-else and nested templates is kept to a minimum, due to the MediaWiki 1.6 limit of 40 levels of if-logic for all nested templates used together. Template {ordomag} was omitted to avoid 2 more levels of nested templates. Template {Precision} had 8 levels, and this template was trimmed to only 5 levels.
  • NOTE S5: The #switch is run with "x" prepended in front of the amount, otherwise a #switch will compare as numeric where "2" would match "2.0" even though "2" is length 1 so "x2" no longer matches with "x2.0" as non-numeric. The #switch will exit on the first match, so smaller lengths are compared first, to avoid extra comparisons for more rare, longer numeric strings up to 41 long.
  • NOTE W6: The check for integers with whole end-zeroes uses typical n=n/10*10, for each power of 10, where whole millions match: {{#ifexpr: {1}=floor( {1}/1E6 )*1E6| }} Previously, {Precision} had tried to use "round" to detect end-zeroes but "round" loses precision at -5, so, n00000 round -5 differs from n00000 slightly, and comparisons to exact rounded amounts failed to match some numbers when 6 or more zeroes "n000000".
  • NOTE Z7: The check on zero for any .00000 compares adding 1 to the amount, versus appending "1" at the end: if the amount is a decimal, then adding 1 will be larger than appending 1 at the end: 0.00 + 1 > 0.001, whereas for whole zero, it would be: 0+1 > 01 as false, due to the value being the same. So, for integer 0, the check rejects: 0+1 > 01 as false; hence whole 0 is integer.

See also

Template:Math templates

) (thank)

(cur | prev) 15:49, 4 September 2010‎ WOSlinker (talk | contribs)‎ . . (2,422 bytes) (+565)‎ . . (apply User:Wikid77's changes to fix values between 0 and 1 as per editrequest.) (thank)
(cur | prev) 22:25, 25 August 2010‎ WOSlinker (talk | contribs)‎ m . . (1,857 bytes) (0)‎ . . (Protected Template:Getprecision: Used by protected template Template:Convert/°F ([edit=sysop] (indefinite) [move=sysop] (indefinite))) (thank)
(cur | prev) 21:46, 18 August 2010‎ Wikid77 (talk | contribs)‎ . . (1,857 bytes) (+430)‎ . . (again, fixed integer 0 as 0, by fixing check for integer) (thank)
(cur | prev) 21:04, 18 August 2010‎ Wikid77 (talk | contribs)‎ . . (1,427 bytes) (+356)‎ . . (Fixed to handle zero: 0 as 0, 0.000 as 3, or 0.0 as 1, etc.) (thank)
(cur | prev) 18:26, 18 August 2010‎ WOSlinker (talk | contribs)‎ . . (1,071 bytes) (-1,460)‎ . . (add documentation subpage) (thank)
(cur | prev) 17:49, 18 August 2010‎ WOSlinker (talk | contribs)‎ . . (2,531 bytes) (+134)‎ . . (add test for Template:Getprecision) (thank)
(cur | prev) 17:21, 15 August 2010‎ Wikid77 (talk | contribs)‎ . . (2,397 bytes) (+561)‎ . . (more examples; added section "Known bugs") (thank)
(cur | prev) 17:03, 15 August 2010‎ Wikid77 (talk | contribs)‎ . . (1,836 bytes) (+1,836)‎ . . (created, as utility template, to get precision of any number, large or negative, using a fast algorithm)
(cur | prev) 01:04, 10 August 2009‎ Huntster (talk | contribs)‎ . . (143 bytes) (-795)‎ . . (Replacing with code from talk page.) (thank)
(cur | prev) 17:22, 6 April 2009‎ Gogo Dodo (talk | contribs)‎ m . . (938 bytes) (-1)‎ . . (Fix spacing) (thank)
(cur | prev) 17:22, 6 April 2009‎ Gogo Dodo (talk | contribs)‎ m . . (939 bytes) (+26)‎ . . () (thank)
(cur | prev) 17:21, 6 April 2009‎ Gogo Dodo (talk | contribs)‎ m . . (913 bytes) (0)‎ . . (Changed protection level for "Template:Precision": High-profile template ([edit=sysop] (indefinite) [move=sysop] (indefinite))) (thank)
(cur | prev) 17:13, 6 April 2009‎ Gogo Dodo (talk | contribs)‎ m . . (913 bytes) (0)‎ . . (Protected Template:Precision: High profile template ([edit=autoconfirmed] (indefinite) [move=sysop] (indefinite))) (thank)
(cur | prev) 17:12, 6 April 2009‎ Gogo Dodo (talk | contribs)‎ m . . (913 bytes) (-871)‎ . . (Reverted edits by Juche Juice (talk) to last version by Gogo Dodo) (thank)
(cur | prev) 17:12, 6 April 2009‎ Juche Juice (talk | contribs)‎ . . (1,784 bytes) (+871)‎ . . (Gogo Dodo rapes babies) (thank)
(cur | prev) 17:10, 6 April 2009‎ Gogo Dodo (talk | contribs)‎ m . . (913 bytes) (-871)‎ . . (Reverted edits by Juche Juice (talk) to last version by Bryan Derksen) (thank)
(cur | prev) 17:09, 6 April 2009‎ Juche Juice (talk | contribs)‎ . . (1,784 bytes) (+1,648)‎ . . (thank)
(cur | prev) 16:26, 22 December 2007‎ Zzuuzz (talk | contribs)‎ m . . (136 bytes) (0)‎ . . (Protected Template:Precision/+: High risk template [edit=sysop:move=sysop]) (thank)
(cur | prev) 16:26, 22 December 2007‎ Zzuuzz (talk | contribs)‎ . . (136 bytes) (-777)‎ . . (protected) (thank)
(cur | prev) 02:56, 2 November 2007‎ Bryan Derksen (talk | contribs)‎ . . (913 bytes) (-51)‎ . . (thank)
(cur | prev) 19:15, 21 October 2007‎ Bryan Derksen (talk | contribs)‎ . . (964 bytes) (+904)‎ . . (uncategorized) (thank)
(cur | prev) 06:20, 4 October 2007‎ Jimp (talk | contribs)‎ . . (60 bytes) (-1)‎ . . (thank)
(cur | prev) 06:16, 4 October 2007‎ Jimp (talk | contribs)‎ . . (61 bytes) (-1)‎ . . (thank)
(cur | prev) 06:15, 4 October 2007‎ Jimp (talk | contribs)‎ . . (62 bytes) (+2)‎ . . (thank)
(cur | prev) 16:55, 3 October 2007‎ Jimp (talk | contribs)‎ . . (60 bytes) (-9)‎ . . (don't need {{{2}}}) (thank)
(cur | prev) 14:54, 3 October 2007‎ Jimp (talk | contribs)‎ . . (69 bytes) (0)‎ . . (reverse 1 & 0) (thank)
(cur | prev) 14:53, 3 October 2007‎ Jimp (talk | contribs)‎ . . (69 bytes) (-20)‎ . . (to 1 or 0) (thank)
(cur | prev) 08:34, 3 October 2007‎ Jimp (talk | contribs)‎ . . (89 bytes) (+1)‎ . . (thank)
(cur | prev) 08:30, 3 October 2007‎ Jimp (talk | contribs)‎ . . (88 bytes) (+10)‎ . . (thank)
(cur | prev) 08:26, 3 October 2007‎ Jimp (talk | contribs)‎ . . (78 bytes) (-835)‎ . . (←Created page with '{{precision/Expression error: Unrecognized punctuation character "{".|{{{1}}}Expression error: Unrecognized punctuation character "{".}}') (thank)
(cur | prev) 22:22, 18 April 2007‎ Quarl (talk | contribs)‎ . . (913 bytes) (+3)‎ . . («+"}} "») (thank)
(cur | prev) 22:21, 18 April 2007‎ Quarl (talk | contribs)‎ . . (910 bytes) (+36)‎ . . (precision/tz) (thank)
(cur | prev) 11:11, 4 April 2007‎ Quarl (talk | contribs)‎ . . (874 bytes) (0)‎ . . («"1" → "0"») (thank)
(cur | prev) 11:11, 4 April 2007‎ Quarl (talk | contribs)‎ . . (874 bytes) (+25)‎ . . («+"", +""») (thank)
(cur | prev) 09:44, 4 April 2007‎ Quarl (talk | contribs)‎ . . (849 bytes) (-17)‎ . . (==) (thank)

(cur | prev) 09:19, 4 April 2007‎ Quarl (talk | contribs)‎ . . (866 bytes) (+67)‎ . . («+"
[edit] [purge] Template documentation

{{#invoke:Message box|tmbox}}


The Template:Precision determines the precision (as a count of decimal digits) for any amount, large or negative, using a fast algorithm. It can also handle a trailing decimal point (such as "15." or "-41.") or trailing zeroes (such as "15.34000" having precision as 5 decimal digits). For fractional input it returns the base ten logarithm of the numerator.

Examples

{{Precision|1111.123456789}} 9
{{Precision|1111.12345678}} 8
{{Precision|1111.1234567}} 7
{{Precision|1111.123456}} 6
{{Precision|1111.12345}} 5
{{Precision|1111111111.12345678}} 8
{{Precision|1111111111.1234567}} 7
{{Precision|1111111111.123456}} 6
{{Precision|1111111111.12345}} 5
{{Precision|1111111111.1234}} 4
{{Precision|1111111111.123}} 3
{{Precision|1111111111.12}} 2
{{Precision|1111111111.1}} 1
{{Precision|1111111111.10}} 2
{{Precision|1111111111.100}} 3
{{Precision|1111111111.1000}} 4
{{Precision|1111111111.10000}} 5
{{Precision|1111111111}} 0
{{Precision|1111111110}} -1
{{Precision|1111111100}} -2
{{Precision|1111111000}} -3
{{Precision|1111110000}} -4
{{Precision|1111100000}} -5
{{Precision|1111000000}} -6
{{Precision|1110000000}} -7
{{Precision|1100000000}} -8
{{Precision|0}} 0
{{Precision|1}} 0
{{Precision|22.45}} 2
{{Precision|22.12345}} 5
{{Precision|22}} 0
{{Precision|22000}} -3
{{Precision|-15.275}} 3
{{Precision|-15.2500}} 4
{{Precision|23000222000111.432}} 3
{{Precision|-15.123}} 3
{{Precision|0.09}} 2
{{Precision|0.88}} 2
{{Precision|880000}} -4
{{Precision|90000000}} -7

Known bugs

  • For numbers in scientific notation, the precision is typically returned as too low by 1 decimal place. Example: {{precision |7.1234E+06}} → -2 (should be precision as 4 decimal digits, not 3).

Technical notes

  • NOTE A1: This template determines the precision of decimals by counting the length of the numeric string (in a #switch comparing lengths of padded strings), then subtracting integer length, minus the decimal point, and minus 1 if negative. For integers, 1 place is subtracted for each trailing 0 on the integer. For fractions, any prior count is cleared x 0, then returns the base ten logarithm of denominator: (..prior...)*0 + (ln denom / ln 10).
  • NOTE D2: The check, for whole integers, compares the amount versus appending "0" at the end: when the amount is a decimal, then the value is unchanged by appending 0 at the end: so 5.23 = 5.230 is true, whereas for whole integers, it would be: 5 = 50 as false, due to values becoming n*10 for integer n. So, for integer n, the check rejects: n = n0 as false; hence n is integer.
  • NOTE M3: The magnitude of the integer portion is calculated by logarithm of the floor of absolute value (divided by natural logarithm of 10 to adjust for e=2.71828*), as: ln (floor( abs(-0.050067) )+0.99 )/ln10 Function floor(x) trims the decimal part, to leave the whole count: 0-9 yield 0, 10-19 as 1, 1000-1999 as 3. The abs(x) avoids floor of negatives, floor(-0.1)= -1, hence using abs(x) ensures -0.1 floors to 0 not -1. Near zero, the +0.99 avoids invalid log of 0, but does not round-up any decimals, already floored as nnn.00. Complexity is 6 operations: floor of abs( {1} ) +0.99 then log10x (lnx ÷ ln10), then floor that logarithm ratio. Decimals -1 < x < 1 yield -1, avoiding log 0.001 = -3.
  • NOTE N4: Nesting of if-else and nested templates is kept to a minimum, due to the MediaWiki 1.6 limit of 40 levels of if-logic for all nested templates used together. Template {ordomag} was omitted to avoid 2 more levels of nested templates. Template {Precision} had 8 levels, and this template was trimmed to only 5 levels.
  • NOTE S5: The #switch is run with "x" prepended in front of the amount, otherwise a #switch will compare as numeric where "2" would match "2.0" even though "2" is length 1 so "x2" no longer matches with "x2.0" as non-numeric. The #switch will exit on the first match, so smaller lengths are compared first, to avoid extra comparisons for more rare, longer numeric strings up to 41 long.
  • NOTE W6: The check for integers with whole end-zeroes uses typical n=n/10*10, for each power of 10, where whole millions match: {{#ifexpr: {1}=floor( {1}/1E6 )*1E6| }} Previously, {Precision} had tried to use "round" to detect end-zeroes but "round" loses precision at -5, so, n00000 round -5 differs from n00000 slightly, and comparisons to exact rounded amounts failed to match some numbers when 6 or more zeroes "n000000".
  • NOTE Z7: The check on zero for any .00000 compares adding 1 to the amount, versus appending "1" at the end: if the amount is a decimal, then adding 1 will be larger than appending 1 at the end: 0.00 + 1 > 0.001, whereas for whole zero, it would be: 0+1 > 01 as false, due to the value being the same. So, for integer 0, the check rejects: 0+1 > 01 as false; hence whole 0 is integer.

See also

Template:Math templates

"») (thank)

(cur | prev) 09:19, 4 April 2007‎ Quarl (talk | contribs)‎ . . (799 bytes) (+799)‎ . . («new: +(104 words)») (thank)

LuisAnton (talkcontribs) 03:50, 4 November 2017 (UTC)