object for deciding wether input is odd or prime number

Sep 23, 2010 at 7:08pm

object for deciding wether input is odd or prime number

Is there an objetc that sends out 0 or 1 wether input is odd or prime?

Sep 23, 2010 at 7:26pm

Do you mean odd or even?

– Pasted Max Patch, click to expand. –
Sep 23, 2010 at 7:32pm

odd/even is dead easy: mask low order bit is one way, or do an integer divide by two and multiply back to see if you get the same number. Tim’s presumably using one of these (haven’t looked at his patch yet).

Prime isn’t quite so easy, but there are a couple of objects to help. If you check out MaxObjects.com (try < http://www.maxobjects.com/?request=prime>) you’ll find some objects that ought to suit your purposes. You may need to patch a bit around them to get what you need.

Sep 23, 2010 at 8:07pm

Never mind, my answer is the same as the patch above:

[% 2] gives 0 for odd, 1 for even numbers.

Sep 23, 2010 at 8:17pm

Yeah, modulo is in my post. Here’s a pointless way of doing it manually because I’m bored :)

expr (((($i1+1)/2)*2)-$i1) – pretty much what Peter said

0 even
1 odd

Sep 23, 2010 at 9:13pm

found this .js on the forum, can’t recall who. brute-force way of determining primes (spits out factors), still plenty fast:

function msg_int(v)
while (v%2==0)
var i=3;
while (i*i
if (v%i==0)
else i+=2;
if (v>1) outlet(0,v);


You must be logged in to reply to this topic.