[PD] div vs. / & i

Mathieu Bouchard matju at artengine.ca
Fri Feb 6 16:12:39 CET 2009


On Fri, 6 Feb 2009, Jonathan Wilkes wrote:

> But I just noticed while scrolling in a number box that they aren't the 
> same when the dividend is negative.  In the source for [div], I see this 
> before doing the division: if (n1 < 0) n1 -= (n2-1); I feel like I'm 
> missing something obvious.  Why does [div] behave this way?

So that (x div y)*y + (x mod y) = x

So div is complementary to mod.

Also, int(x / y)*y + (x % y) = x

So / with i is complementary to %.

And div,mod behave the way that they do so that
   (x+y) mod y =  x mod y
   (x+y) div y = (x div y) + 1

Whereas div with i and % do not, when x and x+y have different signs.

  _ _ __ ___ _____ ________ _____________ _____________________ ...
| Mathieu Bouchard - tél:+1.514.383.3801, Montréal, Québec


More information about the Pd-list mailing list