zl sub not reporting a number that is in the list

    Nov 04 2020 | 12:17 pm
    I have a float number and a list of floats and I send the number and the list to the zl.sub to see where the number is located in the list and the zl.sub tells me it is NOT in the list even though it obviously is.
    Then I copy the message with the EXACT same number and the zl.sub now tells me the correct location of the number in the list.
    What can cause this type of behaviour???
    See Less

    • Nov 04 2020 | 3:03 pm
      the problem seems to be that if you type a float with over 6 decimals into a message box it will somehow remember all the decimals of the number but display only six of them and when you compare that to a same looking number it is not the same. is there a way to "cutoff" all the invisible decimals?
    • Nov 04 2020 | 3:17 pm
      Using an equal operator between two floating point numbers is often dangerous. One would think that using a [round 0.000001] could work, but it's not that simple... The beauty of floating point numbers & computers...
    • Nov 04 2020 | 3:18 pm
      Putting [sprintf %.6f] after the float number seems to help for this situation.
      But it is kind of funny not to know what number you are actually getting. Is there some documentation on this?
    • Nov 04 2020 | 4:17 pm
      Well, comparing floating point numbers is tricky, not just in Max... Best approaches include redesigning to avoid direct comparison of floats, or if you really want to compare floats, you could an equality function with a built-in tolerance (which is pretty much what you do with round, or sprintf rounding). If you google for the topic, you'll find interesting information, with varying degrees of nerdiness. And if you search this forum, you will also find lots of discussions of this topic! https://bitbashing.io/comparing-floats.html https://en.wikibooks.org/wiki/Floating_Point/Epsilon
    • Nov 04 2020 | 4:22 pm
      thank you will check it out