Contents | Index | < Browse | Browse >
Mathematical Calculations & Expression Evaluation:
--------------------------------------------------
Gui4Cli will evaluate a mathematical expression, if enclosed in
brackets with a $ (dollar sign) in front.
x = $(4*2) ; will set x to 8
This can be used anywhere, just as if it were a variable :
Say 'The result is $(45/(2*4.56))n'
Gui4Cli will read brackets as if they were quotes - i.e. you
can have spaces inside the brackets without having to quote
the whole thing :
x = $( 4 * 2 )
You can also have variables in the brackets, but..
BECAREFULL : Gui4Cli allows almost any character to be a part
of a variable name. (This is done because file names - which can
have almost any character in them - can also be variables (env:)
or part of the specification of variables (GuiName/VarName))
So Gui4Cli will also consider things such as +, *, -, / etc to
be included in the variable name if there is no space between
the end of the name and the operator :
x = $($var*3) ; <- wrong
is wrong, because Gui4Cli will try to find variable "var*3"
Gui4Cli will understand the end of a variable name if it is
followed by a space, or a bracket or a '', so
x = $($var *3) ; is correct
x = $(3*$var) ; is correct
x = $($var*3) ; is correct
The available operators are :
+ - * / as you know..
^ means to the power of = 4^2 = 16
Note that to get a square root you can do :
x = $(25^(1/2)) ; 25 to the half = 5
Inside the brackets, you can also use the following math
functions :
abs(x) absolute value of x
sin(x) sin of x
cos(x) cosine of x
tan(x) tagent of x
log(x) logarithm of x
ln(x) natural log of x
exp(x) exp of x
pi = 3.141592654
example :
x = $($MyVariable * pi + tan(0.85)-(4*sin(45)))
I used to know all this stuff, now I can't remember a thing..
The parser which does the actual calculation was written by
Kittiphan Techakittiroj, who put it in the public domain where
from I appropriated it with his blessings and put it to good use.
Here's a calculator : Run Gui Source