Forums > MaxMSP

native rational numbers in Max

Jul 20 2012 | 7:43 am


Does max developers plans to integrate rational numbers to Max?
I’m a bit curious about it because as soon as you want to do some "complex" rythmn things you really need it to keep precision.
the awesome bach library support it in many ways but it is far much slow than native types in max and it become a problem when you need high speed calculation in real time music context
Does anyone know a faster alternative? (external, abstraction)
I know that the next update of bach will clearly increase speed but I’m a bit hurry…



Jul 20 2012 | 7:58 am


No clue about Cycling’s plans of course… but would you mind posting an example in which you think bach’s rationals are the bottleneck? This might be very useful for us to do some profiling.

On the other hand, it won’t be difficult at all implementing a small library of abstractions for dealing with rational numbers – you can express your rationals as lists of numerator and denominator, and the only relatively tricky thing would be computing the lcm.


Jul 20 2012 | 8:49 am


although that’s indeed not an ‘out-of-the-box’ solution, you can deal with rational numbers (as Andrea already pointed out) if you represent them as lists of two numbers (numerator & denominator) quite easily. To compute the lcm and the gcd you could use the appropriate externals from my library as well ([sadam.gcd] and [sadam.lcm]), which are both quite well speed-optimized (see ).

Hope this helps,

Jul 20 2012 | 10:01 am


Look at this patch
I’ve tried to make my own rational abstraction but it is a bit slow too

Jul 20 2012 | 10:03 am

thanks a lot for your help and for your libraries!



Jul 20 2012 | 10:39 am

Thank you for the patch, I’ll look into it asap!

Jul 20 2012 | 10:59 am


actually the [fromsymbol] & friends generate up A LOT of cpu usage. If you use simple lists instead of the symbol-based representation, you can make your [p ratSimp] patch around 10 times faster:

— Pasted Max Patch, click to expand. —

Hope this helps,

Jul 20 2012 | 11:19 am

woaw that’s fast! :)

thanks a lot


Jul 20 2012 | 1:09 pm

i guess what uses the most CPU in bach is the the sublist formatting, not the actual process.

using custom abstractions should be fine, i see no need for an external.

btw, Timersintfloatratnumrat.maxpat simply chrashes my max 5 app.

btw2, i agree with the idea that the most effective solution is to use a list of 2 integers (as opposed to
formatting symbols such as "ratnum_4|3" or similar bs.)

Jul 20 2012 | 1:16 pm

Hi Pierre,

how about this small set of abstractions?

— Pasted Max Patch, click to expand. —

Hope that helps,

Jul 20 2012 | 1:23 pm

This is tangential, but Clojure does support rational numbers and can be used inside Max. Haven’t done it myself, but if you wanted to go all OpenMusic / PWGL on it…

Jul 21 2012 | 11:34 am

Thank you a lot your abstractions it looks really simple and fast!

Thanks to everyone for your contributions



Viewing 12 posts - 1 through 12 (of 12 total)

Forums > MaxMSP