Forums > MaxMSP

Object that knows which number is odd or even

March 10, 2008 | 3:35 pm

Dear Reader,

I would like to know, if there is an object, that can route me a the incoming numbers whether they are odd or even?

Thank you,
all the best,
tEd


March 10, 2008 | 3:45 pm

> I would like to know, if there is an object, that can route me a the incoming numbers whether they are odd or even?

Here’s the point where someone mentions that it’s a common beginner error to imagine that there’s a single object that does anything one wants to do, and that perhaps you might want to think for a moment about what the % object does when its argument is 2.

I’ll leave the patching beyond this as an opportunity for your own edification.


March 10, 2008 | 3:45 pm

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 353 229 32 196617 odd;
#P number 351 207 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 312 207 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 312 184 49 196617 gate 2;
#P newex 378 155 27 196617 + 1;
#P newex 378 130 27 196617 & 1;
#P number 351 101 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 310 229 32 196617 even;
#P connect 1 0 4 1;
#P fasten 1 0 2 0 356 122 383 122;
#P connect 4 1 6 0;
#P connect 4 0 5 0;
#P fasten 3 0 4 0 383 177 317 177;
#P connect 2 0 3 0;
#P window clipboard copycount 8;

There are some things a man does for himself.


March 10, 2008 | 8:20 pm

yes, this helps a lot…
I like to learn from others:) – this is my way and it works!

all the best
tEd



March 11, 2008 | 3:06 pm

Right!

I’ve gotta agree. :)


March 11, 2008 | 4:07 pm

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 138 213 32 196617 odd;
#P comment 99 213 32 196617 even;
#P number 138 187 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 99 187 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 99 129 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 99 157 182 196617 if $i1 % 2 == 0 then $i1 else out2 $i1;
#P connect 0 1 3 0;
#P connect 0 0 2 0;
#P connect 1 0 0 0;
#P window clipboard copycount 6;

Even though i use the [if] object regularly, i don’t know much about it’s ins and outs…is this much worse.


March 12, 2008 | 11:07 am

Using [% 2] instead of [& 1] is sort of softcore.

At the machine level, using modulo (%) is going to take 5-10 as much time as using bit-and (&). But this is talking about nanoseconds; compared to the overhead of message passing in Max, we’re talking about an impact in the area of 0.1% — not something to lose sleep over. OTOH, if you have two easy alternatives, why not take the more efficient one?

Having done a fair amount of time-critical close-to-the-machine programming, it’s simply a habit to minimize the use of if statements and division/modulo operations. But again, once you’re programming at the Max level, this is simply not worth losing sleep over.

In Max programming, the only rule is TMTOWTDI (there’s more than one way to do it). The reason I went for the gate construct was that, to my mind, it better visualizes the dataflow. But if you want to use an if object, sure, go ahead…


March 12, 2008 | 11:50 am

Indeed.

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 79 56 23 196617 abs;
#P toggle 79 152 15 0;
#P newex 79 133 27 196617 > 0.;
#P newex 79 114 27 196617 – 0.;
#P newex 79 95 27 196617 t f i;
#P number 79 39 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 79 76 35 196617 * 0.5;
#P connect 6 0 0 0;
#P connect 1 0 6 0;
#P connect 4 0 5 0;
#P connect 3 0 4 0;
#P connect 2 1 3 1;
#P connect 2 0 3 0;
#P connect 0 0 2 0;
#P window clipboard copycount 7;

On Mar 12, 2008, at 4:07 AM, Peter Castine wrote:

> TMTOWTDI (there’s more than one way to do it)

barry threw
Media Art and Technology

San Francisco, CA
Work: 857-544-3967
Email: bthrew (at) gmail (dot) com
Web: http://www.barrythrew.com


March 12, 2008 | 11:29 pm

Nice patch, Barry.

Just note that it will break for absolute values > 16,777,216.

A patch is not likely to get values that large (or small), but you should be aware of the limitation. It’s dem ol’ 24-bit floatin’ point blues agin, Mama!


March 13, 2008 | 1:29 am

Quote: Peter Castine wrote on Wed, 12 March 2008 05:07
—————————————————-
> Using [% 2] instead of [& 1] is sort of softcore.

In terms of efficiency, yes. But it’s generally been my
experience that the average and relatively innumerate
person is a lot more familiar with dividing by two than
with logical operators, and the idea was to suggest a
way to visualize the problem rather than just writing the
person a patch and perpetuating the cycle of the sequential
grovel.

Your mileage may vary – but you’re absolutely right
about relative microefficiencies.


March 13, 2008 | 4:58 am

All I need is 127.

b

On Mar 12, 2008, at 4:29 PM, Peter Castine wrote:

>
> Nice patch, Barry.
>
> Just note that it will break for absolute values > 16,777,216.
>
> A patch is not likely to get values that large (or small), but you
> should be aware of the limitation. It’s dem ol’ 24-bit floatin’
> point blues agin, Mama!
> –
> —-
> Peter Castine
> Litter Power: < http://www.bek.no/~pcastine/Litter/>
> iCE Tools: <
http://www.dspaudio.com/software/ice/ice_overview.php>
>

barry threw
Media Art and Technology

San Francisco, CA
Work: 857-544-3967
Email: bthrew (at) gmail (dot) com
Web:
http://www.barrythrew.com


March 13, 2008 | 10:49 am

Yeah, I’ve spent too many decades bit-munging.

However, in my teaching experience, most people’s eyes glaze over equally fast when talk goes to modulo as it does to bit masking. Every now and again I’ve got someone who’s done Fortean (Babbittean) Set Theory and then modulo makes lots of sense. But that’s sorta exceptional. I know I did both modulo arithmetic and binary representation in about 3rd grade, but it seems most people were too busy making spitballs to take notice.-

As for the sequential grovel… I was hoping that my Waynesque (as in John) exhortation would be read as "Ah shown you once, now git out ‘n’ do it yerself!"


Viewing 13 posts - 1 through 13 (of 13 total)