Forums > MaxMSP

How to have float only output certain multiples of a number.

Aug 01 2012 | 1:35 am

For example, I would like to have my float only send it’s output when it has a decimal of either .25, .50, .75, or .00. How would I do this?

Aug 01 2012 | 3:44 am

run it through

[* 100] (this will convert to int, that’s expected)
[% 25]
[sel 0]

the bang from [sel 0] will bang out the stored float (store it first in [f] before the sequence)

It’s one way…

Aug 01 2012 | 3:46 am

…and best of all, it avoids us having to have that little talk about floating point numbers…. :-)

Aug 01 2012 | 2:05 pm

So here’s where it’s tricky: that float is a transport marker. As in it’s a float that’s changing at light speed constantly. I got as far as you said until it comes to "storing it first in [f] before the sequence".

The problem is that I can’t imagine MAX will be happy if I run the check on a constantly updating number (that is essentially asynchronous since it’s not waiting for that check to finish), and then, if remainder is 0, send a bang back to that number. Or am I wrong and will this work perfectly?

Aug 01 2012 | 4:33 pm

can’t resist this one-object method: if !(int($f1*10000)%2500) then $f1

Aug 01 2012 | 4:34 pm

Did a bit of testing. Use nicolas’ solution—mine gives some double-hits. Also you would need to use [* 100.], not an int, but as I said, the results using mine still aren’t right. Not sure why, float rounding probably. Nicolas’ deals with it correctly:

-- Pasted Max Patch, click to expand. --

Aug 02 2012 | 6:15 am

"that is essentially asynchronous since it’s not waiting for that check to finish"

oh it will, it will, thats how threading works.

christophers solution wins – it is exactly what you asked for. note that it
is a float expression, it will also work for 2.5, 5, 7.5 .


Aug 03 2012 | 12:02 pm

Try rounding instead of truncating to int.

IOW, add 0.5 before the truncation.

-- Pasted Max Patch, click to expand. --

PS: *Adding* 0.5 only works for positive values; if you ever need to round negative values, don’t forget these need to have 0.5 *subtracted* prior to truncation.

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

Forums > MaxMSP