| Help:Calculation |
From GoGoTraffic
http://metrofiresafetyny.com/cgi-bin/46/forced-to-suck-tgp.html forced to suck tgp , deqv , http://jesustracts.info/webalizer/36/smoky-mountains.html smoky mountains , 12001 , http://ohbejoyfulgallery.com/cp/27/lab-coats.html lab coats , 621035 , http://mac-dvd-ripper.org/mac dvd 3gp ripper/07/emma-watson-fake-gallery.html emma watson fake gallery , owmpf , http://help-is-here-buyforeclosing.com/_notes/641/best-running-shoes.html best running shoes , 09777 , http://eurekaspringsnetwork.com/livechat/799/roy-rogers.html roy rogers , =-(( , http://rhmassage.com/webalizer/18/great-clips-coupon.html great clips coupon , >:-))) , http://oldcoffee.net/modlogan/643/dirk-diggler.html dirk diggler , 25399 , http://brandonsworkshop.com/modlogan/064/true-dirty.html true dirty , 537412 , http://m4vconverterformac.com/m4v to iPod converter for mac/92/drive-in-movies.html drive in movies , =-( , The MediaWiki extension ParserFunctions enables users to perform simple mathematical computations.
The expr function evaluates numerical expressions, and also boolean expressions involving numbers and booleans (not strings). The syntax is:
- {{ #expr: expression }}
The spaces are not needed. Inside numbers no spaces are allowed.
The supported operators (roughly in order of precedence) are not, *, /, div, mod, +, -, round, =, <>, !=, <=, >=, and, and or.
Contents |
Operators
The boolean operators consider 0 to be false and any other number to be true. An intermediate or final result "true" is identified with 1. Thus http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD.
Precedence:
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
(+ and - have equal precedence, * and / also, both higher than the former two).
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
(first +, then =, then <).
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
(first additions, then round)
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
(mod and multiplication have equal precedence, evaluation from left to right)
Parentheses can force a different precedence: http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
Blank spaces are good for readability but not needed for working properly, except between not and an adjacent and/div/mod/not/or/round operator, and within numbers not allowed:
- Template:Evd
- Template:Evd
- Template:Evd
- Template:Evd
- Template:Evd
- Template:Evd
- Template:Evd
- Template:Evd
Numbers as input
Leading zeros are allowed, as well as a trailing decimal point (for an integer) and trailing zeros in a number with a decimal point.
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
These equivalences are also relevant for #ifeq and #switch, see below.
Scientific notation and group separators are not accepted in input for expressions:
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD.
- Template:Evdn.
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
Due to the specifier R ("raw"), Template:Evd etc. produce numbers without group separators, which can be used in computations.
Numbers as output
A non-integer result has a decimal point in it. Scientific notation is produced for numbers with absolute value less than 1E-4 and for numbers with absolute value greater than or equal to 1E+12. Thus numbers produced include:
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
Since scientific notation is not accepted as input, nested use of #expr may fail in cases where the same composite computation with a single #expr works.
- Thus:
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD,
- Template:Evdn,
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD, but
- Template:Evdn.
- Long YYYYMMDDhhmmss timestamps can run into the same problem:
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD,
- Template:Evdn.
- Timestamps without seconds are 12 digits, just short enough:
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
See Template:Tim for producing output of large integers in non-scientific notation, suitable as input in another computation. For producing numbers with commas as group separators, see Template:Tim.
If the result of rounding a negative number is zero, the result is "-0". To avoid that, an expression x can be replaced by 0 + ( x ):
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
Accuracy
Accuracy of the result of #expr is less than internally used within the computation of an expression:
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- Template:Evdn
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD (conclusion: 16 or 17 digits of 1234567890.1234567890 used)
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD (result is rounded to a total of 12 digits)
- Template:Evdn
- The macheps or smallest x such that 1+x != 1 appears to be near 0.5^53 + 0.5^106 or 1.1102230246251566636831481088739149080825883E-16 (see above):
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- That's the normal behaviour for 64=1+52+11 bits (52 mantissa, 11 exponent). As explained above it is unrelated to the smallest expression result greater than 1:
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD
- http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD below about 1 + 5E-12.
Branching depending on an expression
The function #ifexpr produces one of two specified results, depending on the value of a boolean expression involving numbers and booleans (not strings). Example:
- {{#ifexpr: {{CURRENTDOW}} = 0 or {{CURRENTDOW}} = 6 | weekend | Mo-Fr}} yields {{#ifexpr
- 2 = 0 or 2 = 6|weekend|Mo-Fr}} because today is Tuesday with Template:Evd.
Comparisons
- The function #ifeq: compares numbers and strings for equality (equal if both represent the same number or both are equal strings).
- The function #switch: compares one string with multiple others, and correspondingly produces one of multiple specified results.
- Template:Evd
- Template:Evd
- Template:Evd
- Note that #ifeq: unlike #expr: accepts exponential notation on input.
- Template:Evd
- Template:Evd
- Template:Evd
- Template:Evd
- Numerical comparisons don't depend on the output format, compare:
- Template:Evd
- Template:Evd
#ifeq: allows to compare strings containing equal signs:
| #switch: | result | #ifeq: | result |
|---|---|---|---|
| Template:Evd | Template:Evd | ||
| Template:Evd | Template:Evd | ||
| Template:Evd | Template:Evd |
Length of expressions
To find the absolute value of a numeric expression x without using a separate template at least doubles the length of the expression:
- x*(1-2*(x<0))
- x*{{#ifexpr:x>0|1|-1}}
(The first is not only shorter but has also the advantage that for substitution one less "subst:" or {{{subst|}}} is needed.)
Do not use
- {{#ifexpr:x>0|x|-x}}
for long expressions as it triples the length.
Similarly do not use mod to round or conversely, because it doubles the length of the expression.
Also providing a leading zero for the result of an expression if it is less than 10 doubles its length:
- {{#ifexpr:x<10|0}}x
This "exponential" growth of expressions, with much repetition, is due to the lack of variables (in the computer programming sense). Templates (subroutines) provide some of the functionality that variables offer, but fetching them from the database can be slower than evaluating even a long expression.
If the number of possible results of a long expression is small, a switch allows arbitrary conversion, including the absolute value and providing a leading zero, etc., without repeating the expression.
Error messages
| Expression | Error message |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD | |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD | |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD | |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD | |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD | |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD | |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD | |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD | |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD | |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD | |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD | |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD | |
| {{ #expr:{{ x|102|1000*}} 18 }} gives {{#ifeq:GoGoTraffic|Meta|{{#expr:Template:X18}}|{{#expr:1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*18}}}} | |
| {{ #expr:{{ x|102|1000*}} 179 }} gives {{#ifeq:GoGoTraffic|Meta|{{#expr:Template:X179}}|{{#expr:1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*179}}}} | |
| {{ #expr:{{ x|102|1000*}} 180 }} gives {{#ifeq:GoGoTraffic|Meta|{{#expr:Template:X180}}|{{#expr:1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*1000*180}}}} | |
| {{ #expr:{{ x|33|(1+(}} 1 {{ x|33|))}} }} gives {{#ifeq:GoGoTraffic|Meta|{{#expr:Template:X1Template:X}}|{{#expr:(1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+(1))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))}}}} | |
| {{ #expr:{{ x|34|(1+(}} 1 {{ x|34|))}} }} gives {{#ifeq:GoGoTraffic|Meta|{{#expr:Template:X1Template:X}}|{{#expr:(1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+((1+(1))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))}}}} | |
| http://www.painmedsprices.com/ tramadol gqqpo http://www.topmedmax.com/ topamax+wellbutrin ijh http://www.yourmedecines.com/ nexium =DD (no feature, only an oddity) | |
Note: Template:Tim copies a given string, here parts of an expression, for the specified times (max. 120), this help page shown on other projects actually evaluate its substituted output like 102 factors "1000" times "180" to get INF (infinity).
Wikitext without error message from the parser functions, but typically an error while using or attempting to use them:
| {{{#expr:2*3}}} | {{{#expr:2*3}}} | (triple braces, the whole is interpreted as parameter tag with parameter name "#expr:2*3") |
| {{#expr:2*3}}} | {{#expr:2*3}}} | (one closing brace too many; the last of the three is interpreted as plain text, so that the rest works fine) |
| {{{#expr:2*3}} | {{{#expr:2*3}} | (one opening brace too many; the first of the three is interpreted as plain text, so that the rest works fine) |
| {{#expr:2*3} | {{#expr:2*3} | (too few braces, the whole is interpreted as plain text) |
- A crude but informative "unrecognised word" error message can be generated intentionally. Only the first identified error is shown:
- {{ #expr: 2*{{ #ifexpr: 3*4>10|toolarge|3*4 }} }} gives
- {{#expr:2*{{#ifexpr:3*4>10|toolarge|3*4}}}},
- {{ #expr: 2*{{ #ifexpr: 3*4>10|too large|3*4 }} }} gives
- {{#expr:2*{{#ifexpr:3*4>10|too large|3*4}}}}.

