Help! Need alternative for dodgy patching stack overflow

Jun 14, 2010 at 1:18pm

Help! Need alternative for dodgy patching stack overflow

I wish to take an incoming float and keep doubling or halving it until it is within a specific range.

I knew this technique was a bit iffy but thought I could get away with it.

I couldn’t! Can anyone suggest an alternative?

– Pasted Max Patch, click to expand. –
#50889
Jun 14, 2010 at 2:16pm

looks fine until you feed it a 0 or a minus number, do you need to?

#182564
Jun 14, 2010 at 2:38pm

No I dont need to but I am getting a stack overflow message, presumably because the Max engine doesn’t know that this loop could not go on for ever.

But hey I’ve just written my first javascript – seems to have done the job.

//pwrange.js

inlets=2;
outlets=2;

function msg_float(f)

{
outlet(1,f);
if (f<0.2) {

while (f<0.2) {
f=f*2;
}
} else {

while (f>0.4) {
f=f/2;
}

}
outlet (0,f);

}

#182565

You must be logged in to reply to this topic.