I assume you have to flatten the tree into a list somewhere after the subtraction component.
I’m trying to filter some numbers to avoid a division by zero, I tried another way with the “Equals” component, but it has the same problem. I thought Rounding the numbers could help, but the truth looks to be elsewhere…
Unfortunately I have to preserve the data tree structure
Oh . Unfortunately I do not understand data trees that much.
Perhaps try using scripting components and remove all values that equal 0 (zero).
can you post an example file with the numbers/data you are using?
I think it is a rounding issue. The equal is the same case as your first example where you may be checking 0 vs 0.00001
mystery.gh (7.6 KB)
Here are the data I’m using
both @HS_Kim and @Adam_M are correct. It is a rounding issue. Just add the formula that @Adam_M provided above into your expression component. (after the abs component in your def)
if(Round(x,2)=0,1,0)
Thanks for the tip, yes it is a mystery!
It is no mystery https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
It is pretty common knowledge in computational design, engineering, architecture, etc. you should consider everything as tolerance based, not absolute. Even Rhino itself is tolerance based (See Options>Units in Rhino to see your tolerances). Long story short, unless you are using integers, never ask if A=B, always ask if abs(A-B)<tolerance
Years later and this helped me with a similar issue.
I was trying to pass in a text panel of numbers and the expression was functioning but not correctly.
Placing an “Integer” component between the panel and expression input solved it and then I realized I can actually cast the string to an integer directly in the expression by wrapping it as Int(x).