Mathematical operations possible in MWorks

It might be useful to have an implementation of logarithms in MWorks.

Here are some other operations currently available:

sin()
cos()
exp()
rand() – 0 to 1 or rand(low,high)
disc_rand(low, high) – discrete random variable since MWorks does not have a round function
geom_rand(Bernoulli probability, high val)
now()
timerExpired()

The standard logic operators work to (as well as NOT):
!, ==, !=, <, <=, >, >=, &&, ||

Hey Elias,

The MWorks expression parser is based on the STX Expression Parser library. Although I haven’t found a concise summary of all the functions it supports, it does include a natural logarithm:

LOGN(x)

There are some others missing from your list:

ABS(x)
PI()
POW(x,y)
SQRT(x)
TAN(x)

The parser also recognizes boolean and string constants:

true
false
"foo"

Unary operators:

+  - ! NOT

Binary operators:

+ - * / %  && || AND OR

It supports type casts to the types bool, char, short, int, integer, long, byte, word, dword, qword, float, double, string. For example:

(int)(e + 0.4 * 2.5 / (PI() - EXP(-0.644) * 4))

As shown in the last example, it also supports expression grouping via parentheses.

I hope that helps!

Chris

Good to know. That covers the basics. Thanks.

For the benefit of users who may come across this discussion in the future: There’s now a knowledge base article that summarizes the expression syntax supported by MWorks.