[PD] div vs. / & i

Jonathan Wilkes jancsika at yahoo.com
Sun Feb 8 23:26:28 CET 2009


Thanks a lot for the explanation.  Would it be possible to add a help patch to pd, something like the one attached?  div, mod, and % currently default to otherbinops-help.pd but aren't included in that patch.

-Jonathan


--- On Fri, 2/6/09, Mathieu Bouchard <matju at artengine.ca> wrote:

> From: Mathieu Bouchard <matju at artengine.ca>
> Subject: Re: [PD] div vs. / & i
> To: "Jonathan Wilkes" <jancsika at yahoo.com>
> Cc: pd-list at iem.at
> Date: Friday, February 6, 2009, 4:12 PM
> 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


      
-------------- next part --------------
A non-text attachment was scrubbed...
Name: div&mod-help.pd
Type: application/octet-stream
Size: 868 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20090208/bf92c4b9/attachment.obj>


More information about the Pd-list mailing list