[modulo] ?

    Nov 08 2011 | 12:42 pm
    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 08 2011 | 2:18 pm
      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 08 2011 | 3:00 pm
      sorry I mean the [mod] object and [%] doesn't handle negatives value in the same way [mod] does
    • Nov 08 2011 | 3:12 pm
      But there should be a proper documentation how [mod] handles negative values. What you describe looks rather strange to me..
    • Nov 08 2011 | 3:16 pm
      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 08 2011 | 3:21 pm
      use expr?
    • Nov 08 2011 | 3:57 pm
    • Nov 08 2011 | 4:17 pm
      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 08 2011 | 6:19 pm
      Interesting. So does pd have a mathematically correct implementation of modulo?
    • Nov 08 2011 | 8:01 pm
      "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 09 2011 | 11:26 am
      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.