[PD] even/odd conditional mod

Christian Klippel ck at mamalala.de
Wed Aug 2 16:33:20 CEST 2006


hi,

Am Mittwoch, 2. August 2006 15:26 schrieb Frank Barknecht:
> Hallo,
>
> João Miguel Pais hat gesagt: // João Miguel Pais wrote:
> > I have a (variable) flow of ascending numbers triggered from until. I
> > wanted to separate them into even and odd ones, so that each becomes a
> > different treatment (eg. even get 0ed, odd get divided by 2). Is there a
> > modulo option in expr? With that and an [expr if] it should be easy. Or
> > does anyone has any other suggestions?
>
>  [t a a]
>
>  |      \
>
>  [mod 2] \
>
>  [pack 0 0]
>
>  [route 0 1]
>
> I think, expr also has "mod" or "%"
>
> Ciao

if pd provides the bitwise and operator, you may simply check the number for 
its lowest bit ( & 0x01 )... if set, its uneven, if clear, its an even 
number. this works only on integers of course.

but it is definitely cheaper than the modulo operator (cpu-wise)....

greets,

chris




More information about the Pd-list mailing list