Re: [PD] div vs. / i

2009-02-10 Thread Mathieu Bouchard

On Sun, 8 Feb 2009, Jonathan Wilkes wrote:

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.


It would be better if you used [*] and [+] to show that:


(x div y)*y + (x mod y) = x
int(x / y)*y + (x % y) = x


so that this [*] [+] combination is seen as undoing [div] and [mod], and 
that [div] and [mod] are seen as splitting an integer into two parts in a 
reversible way. (same for undoing [/] and [%]).


 _ _ __ ___ _  _ _ ...
| Mathieu Bouchard - tél:+1.514.383.3801, Montréal, Québec___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] div vs. / i

2009-02-08 Thread Jonathan Wilkes
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 ma...@artengine.ca wrote:

 From: Mathieu Bouchard ma...@artengine.ca
 Subject: Re: [PD] div vs. /  i
 To: Jonathan Wilkes jancs...@yahoo.com
 Cc: pd-list@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


  

divmod-help.pd
Description: Binary data
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


[PD] div vs. / i

2009-02-06 Thread Jonathan Wilkes
This is puzzling me.

I've been using [div] as the equivalent to

[/]
|
[int]

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? 

Thanks,
Jonathan



  

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] div vs. / i

2009-02-06 Thread Mathieu Bouchard

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___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list