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

Will's icon

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?

seejayjames's icon

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...

Gregory Taylor's icon

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

Will's icon

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?

Christopher Dobrian's icon

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

seejayjames's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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:

Roman Thilenius's icon

"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 .

-110

Peter Castine's icon

Try rounding instead of truncating to int.

Max Patch
Copy patch and select New From Clipboard in Max.

IOW, add 0.5 before the truncation.

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.