# Mathematical operations possible in MWorks

**URL:** <https://mworks.discourse.group/t/mathematical-operations-possible-in-mworks/663>\
**Category:** Support\
**Created:** [April 23, 2010, 8:13pm UTC](https://mworks.discourse.group/t/mathematical-operations-possible-in-mworks/663 "2010-04-23T20:13:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [April 23, 2010, 8:13pm UTC](https://mworks.discourse.group/t/mathematical-operations-possible-in-mworks/663/1 "2010-04-23T20:13:06Z")

</div>

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):  
!, ==, !=, \<, \<=, \>, \>=, &&, ||

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [April 23, 2010, 9:25pm UTC](https://mworks.discourse.group/t/mathematical-operations-possible-in-mworks/663/2 "2010-04-23T21:25:44Z")

</div>

Hey Elias,

The MWorks expression parser is based on the [STX Expression Parser](http://idlebox.net/2007/stx-exparser/) 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

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [April 24, 2010, 1:32am UTC](https://mworks.discourse.group/t/mathematical-operations-possible-in-mworks/663/3 "2010-04-24T01:32:35Z")

</div>

Good to know. That covers the basics. Thanks.

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [April 2, 2012, 6:25pm UTC](https://mworks.discourse.group/t/mathematical-operations-possible-in-mworks/663/4 "2012-04-02T18:25:49Z")

</div>

For the benefit of users who may come across this discussion in the future: There’s now a [knowledge base article](https://mworks.discourse.group/kb/basics/expression-syntax) that summarizes the expression syntax supported by MWorks.

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 11:43pm UTC](https://mworks.discourse.group/t/mathematical-operations-possible-in-mworks/663/5 "2022-07-19T23:43:27Z")

</div>

Closed on July 19, 2022, 11:43pm UTC


