[Pmwiki-users] number crunching wiki

J. Meijer commentgg
Sat May 22 15:12:49 CDT 2004


Wiki-buffs that want to write their thesis in pmwiki need some mathematical
functions. The code below enables expressions using:

  + - / * %   | & ~ << >>   round()
  sin() asin() sinh() asinh()   cos() acos() cosh() acosh()
  tan() atan() tanh() atanh()  pi()  log() log10() exp()  rand()
  pow() sqrt()   deg2rad() rad2deg()   dechex() hexdec()

Examples of the ((expr=)) format and it more complex form:

  Earth's diameter is roughly ((round(40000/pi(),-2)=))km.
  Synapse Global owes me ((70+2*72.50 = US$?)).
  Synapse Global owes me (((70+2*72.50 =>) US$?)).
  Lots of parenthesis:  ((((9*11)/(9+11))+0.05=)) pairs.
=>
  Earth's diameter is roughly 12700km.
  Synapse Global owes me 70+2*72.50 = US$215.
  Synapse Global owes me (70+2*72.50 =>) US$215.
  Lots of parenthesis:  5 pairs.

The complex form allows the '=' sign in the simple format to be '->' or '=>'
and it to be followed (in order) by a ')', space, uppercase text, one of the
$, ?, ?, EU signs, and finally a question mark '?'. All of these characters
will print as the example shows. The ')' must be matched by an earlier '('.

Make sure you write the expression the way php understands expressions,
otherwise it will complain heartedly :-/

You can make your own special function and add it. String-functions are not
(yet) accepted.

Obvious functions lacking are sumrow() and sumcol()  :-)  Pmwiki could do
number-crunchers a favor and accumulate their output while it is
constructing the table.

Important: you'll have to insert the EU sign manually in the code in the
regexpr (after the '$'), as plain email text is incapable of  representing
it.

-jm



----------------------------------------------------------------------------

# allow inline calculations, formats:
#    ((11+22+33=)) or  (11+22+33 =[>][ ][XX$]?))
$evalfulist='a?sinh?|a?cosh?|a?tanh?|deg2rad|rad2deg|sqrt|pi|log|log10|exp|p
ow|hexdec|dechex|round|rand|';
$evalfulist="/\\(\\(((?:".str_replace('|','\\(|',$evalfulist).'&amp;|&gt;|&l
t;|[0-9.eE+-\\/*%|~\\(\\) ])+?)';
$DoubleBrackets[$evalfulist.'=\\)\\)/se']="eval('return
'.html_entity_decode('$1').';')";
$DoubleBrackets[$evalfulist.'((?:[=-]&gt;|=)?(\\))?
*?[A-Z$???]*?)\?\\)\\)/se']="'$1$2'.eval('return
'.html_entity_decode('$1$3').';')";
# please insert the EU-sign manually after the '$'
# thanks PHP (did I pass the PHP-exam or are there still more bugs?)

-------------------------------------------------
"to be improved soon" (the wiki motto)
"to be much improved without prior notice" (pmotto)





More information about the pmwiki-users mailing list