[modulo] ?

Nov 8, 2011 at 12:42pm

[modulo] ?


I am looking for an equivalent of the [modulo] object (of puredata) in maxmsp

the modulo is a math operator a bit equivalent to % instead that with negative value it doesn’t output the same thing:

(e.g. if I want [modulo 33] of -1 give 0 and [modulo 33] of -2 give 32 [modulo 33] of -33 give 1)

Nov 8, 2011 at 2:18pm

As far as I know puredata has a [mod] operator equivalent to % in Max.

Can you point to some definition/documentation of your [modulo] object?

Nov 8, 2011 at 3:00pm

sorry I mean the [mod] object
and [%] doesn’t handle negatives value in the same way [mod] does

Nov 8, 2011 at 3:12pm

But there should be a proper documentation how [mod] handles negative values.
What you describe looks rather strange to me..

Nov 8, 2011 at 3:16pm

from pd documentation :
[mod] takes a number in its left inlet and will divide that number by either the creation argument or the number given at its left inlet and will produce the value of the remainder at its outlet. If no creation argument is given, then the default value is 1

(nothing about negative values)

Nov 8, 2011 at 3:21pm

use expr?

Nov 8, 2011 at 3:57pm


Nov 8, 2011 at 4:17pm

The Max [%] object handles modulo exactly the way most C implementations do, which is mathematically incorrect.

[expr] may do the trick, otherwise hang a [if $i1 >= 0 then $i1 else out2 $i1] after the [mod] object. Hang a [+] object after the if’s second outlet, make sure the [+] operand is set to your modulo. Et voilà!

Nov 8, 2011 at 6:19pm

Interesting. So does pd have a mathematically correct implementation of modulo?

Nov 8, 2011 at 8:01pm

“Boute argues that Euclidean division is superior to the other ones in terms of regularity and useful mathematical properties, although floored division, promoted by Knuth, is also a good definition. Despite its widespread use, truncated division is shown to be inferior to the other definitions.”

pd (apparently) uses Euclidean, max truncated division.


Time for an attribute?

Nov 9, 2011 at 11:26am

Thanks for the link. Euclidean modulo seems useful in practice (eg. result is always positive).
So based on the article I’ve made an abstraction for usage in Max.

– Pasted Max Patch, click to expand. –

You must be logged in to reply to this topic.