Confusion about "Select" Object

Wan Wan's icon

Is anyone who would help figure out the reason why the SEL object on the right side behaves differently from the sel object left side?

Thank you!!!

Selection Problem.maxpat
text/plain 7.73 KB

mizu's icon

hello
the joy of floats !

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

bzzz

Source Audio's icon

Message never displays more than 6 decimal places,
and if a float like 500.000123 gets received,
it would display 500.
And the patch you posted would behave different on max 6 than on 8.
send message numdecimalplaces 10 or more
to float box to see more than default 6.

Wan Wan's icon

Great explain MIZU and Source Audio! Thank you!!

Roman Thilenius's icon


actually, you can tell from the lower numberbox.

a true 500.0 will always show as "500."; so if you are beeing confronted with "500.0..." it is always another value.

and one must keep in mind that route/select is not a math object. it will not truncate to integer, it will do a type check and treats ints as ints and floats as floats - with the exception of a "true" 500., because for a "true" value type wont matter later.
(as opposed to [ / 500], where the argument puts the obejct in int mode)

my suggestion would be to always write [select 500.] when you are planning to input only floats, and not make use of that extra special case where perfect 500.0s will also be passed from an int comparison.

Roman Thilenius's icon


people always request to be able to write (and send) fractional numbers in max.

there is one situation where it already works:

"300"
[expr $i1*5/3.]
[flonum]
[sel 500]

Roman Thilenius's icon


oh btw. in many other real life situations it is toally okay to have imprecise results.

for example you do not need to calcualte pi yourself, you can type 6 or 11 digits somewhere and be fine with it.

Wan Wan's icon

Thank you Roman for more insight on this issue!

For the display difference about “500.0” and ”500.” you mentioned, I find It’s clearly true when I directly send messages to the [flonum]s. (“499.987789” get “500.0”, “500” get “500.”)

But here comes my new confusion haha! According to MIZU’s explain, It seems both [flonum]s in the original patch I posted have no true “500.0” feed into them, but the left [flonum] shows “500.0” (not true, but accepted by [sel 500] later), and the right one shows “500.” (true, but denied by [sel 500]).

Roman Thilenius's icon


yes, it is even worse. even if you calculate things (or write as many digitas as possible) it sometimes will be enough to produce as accurate results as possible and in other cases, with other operands, it doesnt.

i believe there is no solution to make this better in a programming envoriment at least for values with infinite number of digits such as 0.666...7, because if you do it would just be wrong math and cause new issues.

so the main strategy to avoid running into traps is 1.) to not forward such results to other objects but keep it in an expr wherever possible or 2.) use the right type (int or float) for your route/select/whatever.

apropos expr: your whole patch can be expressed as a single if statement. works with int and float at the end.


#P button 214 237 55 0;
#P button 27 237 55 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 121 106 50 9109513 300;
#P newex 27 187 158 9109513 if (($i1*5/3.)==500) then bang;
#P newex 214 187 158 9109513 if (($i1*5/3.)==500.) then bang;
#P connect 2 0 1 0;
#P connect 2 0 0 0;
#P connect 1 0 3 0;
#P connect 0 0 4 0;
#P window clipboard copycount 5;


Roman Thilenius's icon


here is more fun.

hypothesis: the middle example only works because you´re lucky that the inaccuracy is small enough.

brain teaser: but is the left one safe?

#P button 728 305 55 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 728 271 92 9109513 sel 500;
#P flonum 728 231 183 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 784 67 55 0;
#P newex 728 194 66 9109513 * 0.;
#P newex 784 156 202 9109513 expr 1.666666;
#P message 702 66 50 9109513 300;
#P button 396 303 55 0;
#P newex 396 269 92 9109513 sel 500;
#P flonum 396 229 183 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 452 65 55 0;
#P newex 396 192 66 9109513 * 0.;
#P newex 452 154 202 9109513 expr 1.666667;
#P message 370 64 50 9109513 300;
#P button 75 302 55 0;
#P newex 75 268 92 9109513 sel 500;
#P flonum 75 228 183 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 131 64 55 0;
#P newex 75 191 66 9109513 * 0.;
#P newex 131 153 202 9109513 expr (1.666666666666666666666);
#P message 49 63 50 9109513 300;
#P connect 15 0 16 1;
#P connect 17 0 15 0;
#P connect 18 0 19 0;
#P connect 19 0 20 0;
#P connect 16 0 18 0;
#P connect 14 0 16 0;
#P connect 8 0 9 1;
#P connect 10 0 8 0;
#P connect 7 0 9 0;
#P connect 9 0 11 0;
#P connect 12 0 13 0;
#P connect 11 0 12 0;
#P connect 1 0 2 1;
#P connect 3 0 1 0;
#P connect 4 0 5 0;
#P connect 5 0 6 0;
#P connect 2 0 4 0;
#P connect 0 0 2 0;
#P window clipboard copycount 21;

Wan Wan's icon

Haha I see and I think it’s sensible for me to just love more exprs or try to keep right number type for objects like sel.

Thank you again for your great explanation!