Object to test if given value has decimals?

Jan 3, 2010 at 10:04am

Object to test if given value has decimals?

Hi everybody,
im cracking my brain on how to have a given value
tested to see if it contains decimals
(to eventually have an object spit out all the prime numbers)
thanx in advance for any feedback.

greetz thomas

#47535
Jan 3, 2010 at 12:59pm

You can use [% 1.] into [> 0.] to check for decimal values. Not 100% sure about the prime number thing.

– Pasted Max Patch, click to expand. –
#170999
Jan 3, 2010 at 1:41pm

There’s probably many ways to find out prime numbers. here’s my first thought about it :

– Pasted Max Patch, click to expand. –
#171000
Jan 3, 2010 at 1:56pm

Thanx alot for the reply’s! (onfortunately im running 4.5, so guess i cannot run your patches)

Greetz thom

#171001
Jan 3, 2010 at 5:11pm

here’s the one from timlloyd :

#P toggle 32 119 15 0;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 32 85 28 196617 > 0.;
#P newex 32 62 28 196617 % 1.;
#P flonum 32 36 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P connect 2 0 3 0;
#P connect 1 0 2 0;
#P connect 0 0 1 0;
#P window clipboard copycount 4;

and here’s mine :

#P window setfont “Sans Serif” 9.;
#P window linecount 3;
#P comment 200 78 100 196617 (just for the init if you pasted the patch);
#P window linecount 1;
#P comment 46 33 58 196617 then here;
#P button 165 84 28 0;
#N vpatcher 138 103 563 602;
#P origin 15 0;
#P inlet 226 75 15 0;
#P outlet 20 408 15 0;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 20 370 45 196617 gate 1 0;
#P newex 75 339 33 196617 == 1;
#P newex 75 313 73 196617 mxj list.sum;
#P window linecount 0;
#P newex 226 106 111 196617 loadmess scalarmode 1;
#P window linecount 1;
#P newex 75 287 117 196617 vexpr ($i1 % $i2)==0;
#P newex 182 239 50 196617 zl group;
#P newex 150 216 42 196617 uzi 0 2;
#P newex 150 190 82 196617 t i i;
#P window linecount 0;
#P newex 150 167 26 196617 – 1;
#P newex 55 123 50 196617 t i i i;
#P number 72 95 35 9 1 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P inlet 55 72 15 0;
#P comment 155 317 94 196617 [zl sum] in max 5;
#P fasten 11 0 12 0 80 363 25 363;
#P connect 12 0 13 0;
#P connect 1 0 3 0;
#P connect 2 0 3 0;
#P connect 3 0 12 1;
#P connect 9 0 8 0;
#P connect 3 1 8 0;
#P connect 8 0 10 0;
#P connect 10 0 11 0;
#P fasten 3 2 4 0 100 153 155 153;
#P connect 4 0 5 0;
#P connect 5 0 6 0;
#P connect 6 2 7 0;
#P connect 7 0 8 1;
#P connect 5 1 7 1;
#P connect 14 0 9 0;
#P pop;
#P newobj 94 140 81 196617 p passPrimeOnly;
#P newex 94 180 35 196617 print;
#P newex 54 90 50 196617 uzi 100 1;
#P button 54 50 28 0;
#P comment 162 58 100 196617 bang here first;
#P connect 1 0 2 0;
#P connect 4 0 3 0;
#P connect 5 0 4 1;
#P connect 2 2 4 0;
#P window clipboard copycount 8;

#171002
Jan 4, 2010 at 11:48am

here’s the shortest way I’ve found to get the prime factorization of any number, using javascript. I wrote a similar one but then I found this on the forum and it’s pretty much as streamlined as it gets. tests for all factors of 2, then goes to 3 and then adds 2 for each new test. so it won’t try any other even numbers after that.

you can add a bit of code to say when an output number is prime or not, and collect them into a list of as many primes as you want.

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

#171003

You must be logged in to reply to this topic.