MWorks expression feature request - low priority

Mark Histed's Avatar

Mark Histed

30 Jul, 2012 01:18 PM

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

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

  1. Support Staff 1 Posted by Christopher Sta... on 10 Aug, 2012 08:27 PM

    Christopher Stawarz's Avatar

    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

  2. Support Staff 2 Posted by Christopher Sta... on 16 Aug, 2012 06:03 PM

    Christopher Stawarz's Avatar

    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/stat...

    Thanks,
    Chris

  3. 3 Posted by Mark Histed on 16 Aug, 2012 10:20 PM

    Mark Histed's Avatar

    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. 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

  4. Support Staff 4 Posted by Christopher Sta... on 17 Aug, 2012 09:29 PM

    Christopher Stawarz's Avatar

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

    Thanks,
    Chris

  5. Support Staff 5 Posted by Christopher Sta... on 05 Oct, 2012 06:03 PM

    Christopher Stawarz's Avatar

    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

  6. Christopher Stawarz closed this discussion on 05 Oct, 2012 06:03 PM.

  7. 6 Posted by Mark Histed on 05 Oct, 2012 10:36 PM

    Mark Histed's Avatar

    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

  8. Support Staff 7 Posted by Christopher Sta... on 10 Oct, 2012 03:23 PM

    Christopher Stawarz's Avatar

    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: nearest integer not less than the given value
    • floor: nearest integer not greater than the given value
    • 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, 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

  9. 8 Posted by Mark Histed on 10 Oct, 2012 03:30 PM

    Mark Histed's Avatar

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

  10. Christopher Stawarz closed this discussion on 10 Oct, 2012 03:32 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac