Template talk:Add
From Virtualsoil
Simple computations
- For a MediaWiki extension, currently not implemented in Wikimedia projects, providing an alternative method of performing simple calculations, see Calc.
Simple additions and multiplications can be performed based on concatenation, using the unary numeral system: when 2 is represented by 11 and 3 by 111, then concatenation gives 11111, which can be converted to 5, see m:Template:Add (talk, backlinks, edit) and m:Template:Multiply (talk, backlinks, edit). An additional parameter allows not only to display the result 5, but also to call a template of choice with parameter 5.
Required auxiliary templates:
- for every value m used as first operand a template calcm containing {{calc{{{2}}}{{{1}}}|m digits "1" |{{{3}}}}}, see e.g. m:Template:Calc2 (talk, backlinks, edit)
- for every value n used as second operand for addition a template calcAn containing {{countn digits "1"{{{1}}}|{{{2}}}}}, see e.g. m:Template:CalcA3 (talk, backlinks, edit)
- for every value n used as second operand for multiplication a template calcBn containing {{countn times {{{1}}}|{{{2}}}}}, see e.g. m:Template:CalcM3 (talk, backlinks, edit)
- for every result r a template countr digits "1" containing {{{{{1}}}|r }}, see e.g. m:Template:Count11111 (talk, backlinks, edit)
- the template that one wants to call with the result as parameter; if one just wants to display the result, or use it in a link target, or in an image tag, one uses m:Template:X1 (talk, backlinks, edit)
In view of the maximum length of 255 for page names, the maximum result can be 250.
Note that for any computation one can prepare an array with all results, but the amount of work to do that is proportional to the number of pairs (m,n) that one wants to use, while above the amount of work is only proportional to the sum of the number of values of m, n, and r.