Template:Evalns

From SacredWiki
Jump to navigation Jump to 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 12.
  • {{evalns|1234567890*12}} gives 14814814680.
  • {{evalns|1234567890*1234567890}} gives 1.5241578750191E+18.
  • {{eval|2*{{evalns|1234567890*1234567890}}}} gives Template:Eval.

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 Template:Eval.

But it cannot detect all errors:

  • {{eval|2*{{evalns|1234567890*1.2}}}} gives Template:Eval.
  • {{eval|2*{{evalns|1234567890*1.2.3}}}} also gives Template:Eval !
  • {{eval|2*{{evalns|1234567890*1.2.3.4567890}}}} also gives Template:Eval !
  • {{eval|2*{{evalns|1234567890*1.2.3.4.5.6.7.8.9.0}}}} also gives Template:Eval !
  • {{eval|2*{{evalns|1234567890*1.2.3.4.5.6.7.8.e-1}}}} also gives Template:Eval !
  • {{eval|2*{{evalns|1234567890*1.2e3.4.5.6.7.8.e-1}}}} now gives Template:Eval !
  • {{eval|2*{{evalns|1234567890*1.2e3.e.5.6.7.8.e-1}}}} now gives Template:Eval !
  • {{eval|2*{{evalns|1234567890*1.2e3.4e5.6.7.8.e-1}}}} now gives Template:Eval !

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.