# MWorks expression feature request - low priority

**URL:** https://mworks.discourse.group/t/mworks-expression-feature-request-low-priority/636
**Category:** Support
**Created:** [July 30, 2012, 1:18pm UTC](https://mworks.discourse.group/t/mworks-expression-feature-request-low-priority/636 "2012-07-30T13:18:26Z")
**Posts on this page:** 10
**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: [July 30, 2012, 1:18pm UTC](https://mworks.discourse.group/t/mworks-expression-feature-request-low-priority/636/1 "2012-07-30T13:18:26Z")

</div>

Hi Chris,

It would be useful to have XML/STX functions for rounding to a set number of decimal places and a set number of significant digits. I’d be happy with a work-alike to matlab roundto.m and say the third-party chop.m:  
[http://www.liv.ac.uk/pjgiblin/maths/mfiles/chop.m](http://www.liv.ac.uk/pjgiblin/maths/mfiles/chop.m)

It’s possible to do this with int casting but makes for very complicated expressions and is difficult to get right.

Very low-priority - this doesn’t stop us from doing anything important.

Thanks!  
Mark

---

<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: [August 10, 2012, 8:27pm UTC](https://mworks.discourse.group/t/mworks-expression-feature-request-low-priority/636/2 "2012-08-10T20:27:04Z")

</div>

Hi Mark,

Sorry for the delay in responding. I’ve opened a ticket for this and will try to get these functions in to the upcoming 0.5 release.

Cheers,  
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: [August 16, 2012, 6:03pm UTC](https://mworks.discourse.group/t/mworks-expression-feature-request-low-priority/636/3 "2012-08-16T18:03:13Z")

</div>

Hi Mark,

> I’d be happy with a work-alike to matlab roundto.m

I assumed this was a MATLAB built-in, but it appears that it isn’t. Is this the function you’re referring to?

[http://code.google.com/p/pmtk3/source/browse/trunk/matlabTools/stats/roundto.m](http://code.google.com/p/pmtk3/source/browse/trunk/matlabTools/stats/roundto.m)

Thanks,  
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: [August 16, 2012, 10:20pm UTC](https://mworks.discourse.group/t/mworks-expression-feature-request-low-priority/636/4 "2012-08-16T22:20:04Z")

</div>

I don’t know what I was thinking in the earlier message, but I think what would be best is to add a  
round() and a ceil() function that act like C’s - e.g. [round(3) - Linux man page](http://linux.die.net/man/3/round).  
floor() is nice for symmetry but can be emulated by casting, right?

Then roundto() can be implemented in the XML by round(num\*10**x)/10**x.

Thank you,  
Mark

---

<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: [August 17, 2012, 9:29pm UTC](https://mworks.discourse.group/t/mworks-expression-feature-request-low-priority/636/5 "2012-08-17T21:29:37Z")

</div>

OK, that’s even easier. I’ll add `round`, `ceil`, and `floor` to the parser.

Thanks,  
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: [October 5, 2012, 6:03pm UTC](https://mworks.discourse.group/t/mworks-expression-feature-request-low-priority/636/6 "2012-10-05T18:03:52Z")

</div>

Hi Mark,

I’ve added `ceil`, `floor`, and `round` functions to the expression parser. They’ll be available in tonight’s nightly build.

Cheers,  
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: [October 5, 2012, 10:36pm UTC](https://mworks.discourse.group/t/mworks-expression-feature-request-low-priority/636/7 "2012-10-05T22:36:37Z")

</div>

Great! When you get a chance can you document how they work for negative numbers? (i.e. round/truncate toward zero or toward -Inf)

(I was recently having trouble figuring out how mod worked in MWorks for negative signed integers and eventually just gave up and worked around it.)

Thanks for all this work, Chris.

Mark

---

<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: [October 10, 2012, 3:23pm UTC](https://mworks.discourse.group/t/mworks-expression-feature-request-low-priority/636/8 "2012-10-10T15:23:53Z")

</div>

Hi Mark,

> When you get a chance can you document how they work for negative numbers? (i.e. round/truncate toward zero or toward -Inf)

They’re simple wrappers around the corresponding C++ standard library functions, which return the following results:

- [ceil](http://en.cppreference.com/w/cpp/numeric/math/ceil): nearest integer not less than the given value
- [floor](http://en.cppreference.com/w/cpp/numeric/math/floor): nearest integer not greater than the given value
- [round](http://en.cppreference.com/w/cpp/numeric/math/round): nearest integer, rounding away from zero in halfway cases

> (I was recently having trouble figuring out how mod worked in MWorks for negative signed integers and eventually just gave up and worked around it.)

The expression parser’s modulo operation uses the C++ modulo operator. In the case of negative operands, the C++98 standard leaves the sign of the result up to the implementation. (Or so says [Wikipedia](http://en.wikipedia.org/wiki/Modulo_operation), at least.) However, both gcc and clang appear to follow the C++11 standard in this regard and give the result the same sign as the dividend.

I don’t know if that makes things any clearer, but there it is.

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: [October 10, 2012, 3:30pm UTC](https://mworks.discourse.group/t/mworks-expression-feature-request-low-priority/636/9 "2012-10-10T15:30:45Z")

</div>

Thanks for putting this together, Chris, it’s very helpful. I appreciate you checking the current Mac OS behavior. Mark

---

<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:32pm UTC](https://mworks.discourse.group/t/mworks-expression-feature-request-low-priority/636/10 "2022-07-19T23:32:57Z")

</div>


