can't seem to select specific numbers with [sel] and [if]

Ahti Ta's icon

I have a weird situation in one of my patch - it does not select some specific numbers ( 0. 0.05 0.1 and 0.2 work as expected but 0.15 and 0.25 do not).

Can't quite figure out what the issue might be and how to fix this. I tried with both [sel] and [if] object, but with little success.

Here's the patch:

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

Source Audio's icon

That definitely is max bug - it should not behave like that.
I would suggest to use ints instead of floats.
If You have to keep float for whatever reason, multiply result
x 100 like {if $f1 * 100 == 25 then 1 else 0} that should work.
Match object does behave correctly, {match 0.25}

Max 4 & 5 do not have that problem, it is one of the "improvements"
in max 6 and higher

AnBe's icon

It's a significant bug.
Please report to the cycling74.

jvkr's icon

No, its not a bug, it is not specific enough ;)

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

Source Audio's icon

Hmm ...


What makes the difference between 0.25 and 0.01 ?

jvkr's icon

In 7.3.4 it is different for 0.01... The various results can all be explained, but the bottomline is to try avoid comparing float values.

Source Audio's icon

That's a good point

Gregory Taylor's icon

It's always good to be aware of how computers represent floating-point values. I wonder what a search of the Forum would tell us is the average span of time between when this kind of question comes up....

http://www.lahey.com/float.htm

Ahti Ta's icon

Hmm. Yes, multiplying them to ints could work as a workaround but it's a weird anomaly still.
It's not that the sel or if object don't recognize 0.25 or 0.15 at all (in a separate patch, just one sel or if object by its own does) but just in that specific context they don't (while 0.05 oddly works as expected).

Could it be do something with [round]?

Source Audio's icon

In Your case - round objects outputs this long float which one can see only if You increase the number of decimal places for the float box, but You can't see it in a message because max simply hides the extra precision places, but if You click on the message all the float places will be output anyway. If You connect output of round object to different objects that can store floats, the results will be different, because they truncate and round differently.
Some objects have option to set "precision $1" , like text or capture, up to 256 places but for example coll or umenu don't. If You put a float like
0.24999959766864776611328125 into umenu
it will display 0.25, but if You send that float out of umenu it could become
0.24999959766864776611328125 again, depending on receiver object.
Actually it rounds the visible float depending on the float itself up to 6 decimal places, but could store 26 decimal places.
 "if" object is obviously handling floats differently then for example "==" object, and I guess because "if" object should be able to perform calculations,
whereas "==" object not.
What you see is not allways what you get...
Welcome to max world.