Template:Evalns

From TrainzOnline
Revision as of 01:06, 8 July 2013 by Fabartus (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
{{{{{subst|}}}#if:{{{{{subst|}}}#ifexpr:{{{{{subst|}}}#expr:{{{1}}}}}}}|({{{1}}})|{{{{{subst|}}}#expr:{{{1}}}}}}}

EVALuate, but No Scientific notation.

This template can be used to evaluate an expression, if the result has to be suitable as input for further expressions. If the output is not valid as input, the expression is just reproduced, enclosed in parentheses. Note that numbers in scientific notations were initially NOT suitable for input of expressions, hence the name of this template. This is no longer the case as demonstrated below.

  • {{evalns|3*4}} gives {{#if:{{#ifexpr:{{#expr:3*4}}}}|(3*4)|{{#expr:3*4}}}}.
  • {{evalns|1234567890*12}} gives {{#if:{{#ifexpr:{{#expr:1234567890*12}}}}|(1234567890*12)|{{#expr:1234567890*12}}}}.
  • {{evalns|1234567890*1234567890}} gives {{#if:{{#ifexpr:{{#expr:1234567890*1234567890}}}}|(1234567890*1234567890)|{{#expr:1234567890*1234567890}}}}.
  • {{eval|2*{{evalns|1234567890*1234567890}}}} gives {{#if:{{#ifexpr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1234567890}}}}|(1234567890*1234567890)|{{#expr:1234567890*1234567890}}}}}}|[expression "2*{{#if:{{#ifexpr:{{#expr:1234567890*1234567890}}}}|(1234567890*1234567890)|{{#expr:1234567890*1234567890}}}}" is wrong]|{{#expr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1234567890}}}}|(1234567890*1234567890)|{{#expr:1234567890*1234567890}}}}}}}}.

The case where evalns returns the input expression in parentheses is when it detects an error when trying to evaluate it as an numeric expression:

  • {{eval|2*{{evalns|1234567890*1x2.34567890}}}} gives {{#if:{{#ifexpr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1x2.34567890}}}}|(1234567890*1x2.34567890)|{{#expr:1234567890*1x2.34567890}}}}}}|[expression "2*{{#if:{{#ifexpr:{{#expr:1234567890*1x2.34567890}}}}|(1234567890*1x2.34567890)|{{#expr:1234567890*1x2.34567890}}}}" is wrong]|{{#expr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1x2.34567890}}}}|(1234567890*1x2.34567890)|{{#expr:1234567890*1x2.34567890}}}}}}}}.

But it cannot detect all errors:

  • {{eval|2*{{evalns|1234567890*1.2}}}} gives {{#if:{{#ifexpr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2}}}}|(1234567890*1.2)|{{#expr:1234567890*1.2}}}}}}|[expression "2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2}}}}|(1234567890*1.2)|{{#expr:1234567890*1.2}}}}" is wrong]|{{#expr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2}}}}|(1234567890*1.2)|{{#expr:1234567890*1.2}}}}}}}}.
  • {{eval|2*{{evalns|1234567890*1.2.3}}}} also gives {{#if:{{#ifexpr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2.3}}}}|(1234567890*1.2.3)|{{#expr:1234567890*1.2.3}}}}}}|[expression "2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2.3}}}}|(1234567890*1.2.3)|{{#expr:1234567890*1.2.3}}}}" is wrong]|{{#expr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2.3}}}}|(1234567890*1.2.3)|{{#expr:1234567890*1.2.3}}}}}}}} !
  • {{eval|2*{{evalns|1234567890*1.2.3.4567890}}}} also gives {{#if:{{#ifexpr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2.3.4567890}}}}|(1234567890*1.2.3.4567890)|{{#expr:1234567890*1.2.3.4567890}}}}}}|[expression "2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2.3.4567890}}}}|(1234567890*1.2.3.4567890)|{{#expr:1234567890*1.2.3.4567890}}}}" is wrong]|{{#expr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2.3.4567890}}}}|(1234567890*1.2.3.4567890)|{{#expr:1234567890*1.2.3.4567890}}}}}}}} !
  • {{eval|2*{{evalns|1234567890*1.2.3.4.5.6.7.8.9.0}}}} also gives {{#if:{{#ifexpr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2.3.4.5.6.7.8.9.0}}}}|(1234567890*1.2.3.4.5.6.7.8.9.0)|{{#expr:1234567890*1.2.3.4.5.6.7.8.9.0}}}}}}|[expression "2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2.3.4.5.6.7.8.9.0}}}}|(1234567890*1.2.3.4.5.6.7.8.9.0)|{{#expr:1234567890*1.2.3.4.5.6.7.8.9.0}}}}" is wrong]|{{#expr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2.3.4.5.6.7.8.9.0}}}}|(1234567890*1.2.3.4.5.6.7.8.9.0)|{{#expr:1234567890*1.2.3.4.5.6.7.8.9.0}}}}}}}} !
  • {{eval|2*{{evalns|1234567890*1.2.3.4.5.6.7.8.e-1}}}} also gives {{#if:{{#ifexpr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2.3.4.5.6.7.8.e-1}}}}|(1234567890*1.2.3.4.5.6.7.8.e-1)|{{#expr:1234567890*1.2.3.4.5.6.7.8.e-1}}}}}}|[expression "2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2.3.4.5.6.7.8.e-1}}}}|(1234567890*1.2.3.4.5.6.7.8.e-1)|{{#expr:1234567890*1.2.3.4.5.6.7.8.e-1}}}}" is wrong]|{{#expr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2.3.4.5.6.7.8.e-1}}}}|(1234567890*1.2.3.4.5.6.7.8.e-1)|{{#expr:1234567890*1.2.3.4.5.6.7.8.e-1}}}}}}}} !
  • {{eval|2*{{evalns|1234567890*1.2e3.4.5.6.7.8.e-1}}}} now gives {{#if:{{#ifexpr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2e3.4.5.6.7.8.e-1}}}}|(1234567890*1.2e3.4.5.6.7.8.e-1)|{{#expr:1234567890*1.2e3.4.5.6.7.8.e-1}}}}}}|[expression "2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2e3.4.5.6.7.8.e-1}}}}|(1234567890*1.2e3.4.5.6.7.8.e-1)|{{#expr:1234567890*1.2e3.4.5.6.7.8.e-1}}}}" is wrong]|{{#expr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2e3.4.5.6.7.8.e-1}}}}|(1234567890*1.2e3.4.5.6.7.8.e-1)|{{#expr:1234567890*1.2e3.4.5.6.7.8.e-1}}}}}}}} !
  • {{eval|2*{{evalns|1234567890*1.2e3.e.5.6.7.8.e-1}}}} now gives {{#if:{{#ifexpr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2e3.e.5.6.7.8.e.1}}}}|(1234567890*1.2e3.e.5.6.7.8.e.1)|{{#expr:1234567890*1.2e3.e.5.6.7.8.e.1}}}}}}|[expression "2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2e3.e.5.6.7.8.e.1}}}}|(1234567890*1.2e3.e.5.6.7.8.e.1)|{{#expr:1234567890*1.2e3.e.5.6.7.8.e.1}}}}" is wrong]|{{#expr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2e3.e.5.6.7.8.e.1}}}}|(1234567890*1.2e3.e.5.6.7.8.e.1)|{{#expr:1234567890*1.2e3.e.5.6.7.8.e.1}}}}}}}} !
  • {{eval|2*{{evalns|1234567890*1.2e3.4e5.6.7.8.e-1}}}} now gives {{#if:{{#ifexpr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2e3.4e5.6.7.8.e-1}}}}|(1234567890*1.2e3.4e5.6.7.8.e-1)|{{#expr:1234567890*1.2e3.4e5.6.7.8.e-1}}}}}}|[expression "2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2e3.4e5.6.7.8.e-1}}}}|(1234567890*1.2e3.4e5.6.7.8.e-1)|{{#expr:1234567890*1.2e3.4e5.6.7.8.e-1}}}}" is wrong]|{{#expr:2*{{#if:{{#ifexpr:{{#expr:1234567890*1.2e3.4e5.6.7.8.e-1}}}}|(1234567890*1.2e3.4e5.6.7.8.e-1)|{{#expr:1234567890*1.2e3.4e5.6.7.8.e-1}}}}}}}} !

In other words, the evaluation of constant numbers stops at the second dot found, and the rest is simply ignored if it only contains superfluous characters that may be acceptable in constant numbers, but if there's a "e", it is treated to compute a "strange" product... This just reveals that in fact the scientific notation is still not recognized as such, but instead "e" is handled like a binary operator between two numbers that are evaluated separately.

This page has it's origination in the Wikimedia Foundation's development website Meta-wiki or has been exported and is now part of the newer Mediawiki software resources website for assisting new wikis with startup organization and has been copied according to the terms of the (CC-BY-SA-3.0), the GFDL standard GNU pulic license or the source file(s) is/are in the public domain.
Personal tools