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

Aug 1, 2012 at 1:35am

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

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?

#63808
Aug 1, 2012 at 3:44am

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…

#230103
Aug 1, 2012 at 3:46am

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

#230104
Aug 1, 2012 at 2:05pm

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?

#230105
Aug 1, 2012 at 3:03pm

Hello,

as seejayjames suggested ; and this work perfectly…

– Pasted Max Patch, click to expand. –
#230106
Aug 1, 2012 at 4:33pm

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

#230107
Aug 1, 2012 at 4:34pm

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. –
#230108
Aug 2, 2012 at 6:15am

“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

#230109
Aug 3, 2012 at 12:02pm

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.

#230110

You must be logged in to reply to this topic.