## zl compare, equal, select, not working output of expr

May 12, 2011 at 12:34pm

# zl compare, equal, select, not working output of expr

Hello everyone,
zl compare, equal, select, not working output of expr.
Do you have the same problem?

Thank you

Mac mini 2010
OS 10.6.7
Max / MSP / Jitter 5.1.8

– Pasted Max Patch, click to expand. –
#57090
May 12, 2011 at 1:33pm

I would say its because you cannot express the ratio 4/3 exactly as a decimal or as a binary. (1.333333 is not the same number as 4/3). Maybe someone who knows more about how 32-bit floats are represented in max could shed light on this

#204515
May 12, 2011 at 4:28pm

Hello Terry,
I understand the “problem”, but who to trust if we can not count on expr :)

#204516
May 12, 2011 at 6:35pm

The reason for this is that the number displayed in the message box as the output of expr is being truncated. When we look at the float in a float object set to 10 decimal places we can see that the value is not equal to 1.333333, therefore zl, == and sel are all behaving correctly.

To work around this, you could use if to compare the float to the original calculation, or you could convert the float into a symbol and then use zl compare or select. These methods are shown in the patch below.

– Pasted Max Patch, click to expand. –
#204517
May 13, 2011 at 11:25am

@LLT: You can trust expr (to the limits of 32-bit floating point). It’s typing numbers into object boxes you need to be wary of.

Basically, you cannot reliably type floating-point values into object boxes and compare these against calculated values. The calculated values is not restricted to [expr] objects; all the arithmetic objects (plus/minus/times/divide/modulo/etcetc.) will have the same kinds of behavior.

If you want reliable comparisons, use integers. If you insist on typing floats into object and message boxes, the only accurate ones are those that are “round” in binary: sums of 1/2, 1/4, 1/8, 1/16, etc.

#204518
May 13, 2011 at 1:16pm

so all you have to do is write “4/3″ instead of 1.333333.

#204519
May 17, 2011 at 8:14am

Hello everyone,