DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:calc

This is an old revision of the document!


Calc Plugin

Compatible with DokuWiki

2008-05-05

plugin Petite calculatrice / Lil calculator

Last updated on
2008-09-11
Provides
Syntax

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to pot

Tagged with calculation, math

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 ;-)

I get an error: Parse error: syntax error, unexpected '{' in /dokuwiki/lib/plugins/calc/syntax.php on line 118:-(

plugin/calc.1267643202.txt.gz · Last modified: 2010-03-03 20:06 by 74.93.99.97

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki