Calc Plugin

calc plugin by Etienne M.
Petite calculatrice / Lil calculator

Last updated on 2008-09-11. Provides Syntax.
Compatible with DokuWiki 2008-05-05.

Tagged with calcul, calculation, calculator, calculatrice, math.

Download http://emauvais.multimania.com/dokuwiki/calc.tar.gz

Description

Syntax

  • calc:[your_math_expression]= → result
  • calc:[your_math_expression]>= → your_math_expression = result

Examples

  • calc:2+3*5= → 17
  • calc:-1234.56*78.9= → -9,629.568
  • calc:sin(pi()/4)= → 0.707106781187
  • calc:round(exp(1),3)= → 2.718
  • calc:(1+sqrt(5))/2= → 1.61803398875
  • You can display the expression before the result adding a ”>” before the ”=”
    • calc:2+3*5>= → 2+3*5 = 17
  • The plugin handles errors
    • calc:5/0= → “Calc error: Division by zero”
    • calc:sqrt(-1)= → “Bad value…”
    • calc:unauthorized_function(12)= → “Calc error: syntax error, unexpected ';'”

Tips

  • You can customize your decimal and thousand separators in the lang/xx/lang.php file (xx is your language code: fr, en…).
  • A comment is added in the source code of the page before the calculation: you can see what expression has really been processed by the plugin.
  • You can also use this plugin to format a single number. Ex: calc:1234567890= → 1,234,567,890.

Security

  • This plugin uses the php eval() function, but it removes all functions that are not mathematical functions before doing the eval().
  • It also removes every ”;” and “$” char before doing the evaluation.
  • Tell me if you see a security break using this plugin.

Version history

  • 2008-09-08: first one!
  • 2008-09-10: doesn't try to format string results (like those sent by base_convert)
  • 2008-09-11: prevents XSS

Discussion

  • Tell me…

I dreamed about it, and you made it. Thank you so much ! fab


You're welcome ;-)
 
plugin/calc.txt · Last modified: 2009/01/03 23:14 by 67.170.0.207
 

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported

Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsDarcsXRefTranslate