Hi,
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?
Thanks,
Joao
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 "%"
Frank Barknecht _ ______footils.org_ __goto10.org__
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
Hallo, Christian Klippel hat gesagt: // Christian Klippel wrote:
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.
This is a good idea. THe object to use is [& 1] as in attached patch.
Frank Barknecht _ ______footils.org_ __goto10.org__
On 8/2/06, Frank Barknecht fbar@footils.org wrote:
Hallo, Christian Klippel hat gesagt: // Christian Klippel wrote:
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.
This is a good idea. THe object to use is [& 1] as in attached patch.
Is this more efficient?
Hallo, Chuckk Hubbard hat gesagt: // Chuckk Hubbard wrote:
This is a good idea. THe object to use is [& 1] as in attached patch.
Is this more efficient?
I'd do an uneducated guess that comparison or two ints is more efficient than float multiplication, but I also guess that this won't matter unless you do a lot of even/odd separations.
Frank Barknecht _ ______footils.org_ __goto10.org__
João Miguel Pais wrote:
Hi,
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?
What about the attached patch?
br, Piotr