Equality test error

I was trying to test if the point distance and line length will give the same results for a given set of points and it turned out that it’s not 100% the same. I traced some of the unequal ones. In the panel, with 12 decimal places, they are perfectly the same. However, the equality function gives out False.

Equality test.gh (11.9 KB)

P.S. the formatting function is from here.

Your file lacks a referenced point from the Rhino file. You can just internalise the numbers directly through, you don’t have to include the entire logic which creates them.

If you want to see what a number is really like, use the Format component with the formatting mask {0:R}. This guarantees a lossless conversion from number to text.

1 Like

Thank you.

Now they are different in the last 2 digits.
But why?

With the internalised point:

Equality test.gh (10.3 KB)

Basically, you can’t trust digital mathematics. There’s always going to be garbage in the least significant digits after a calculation, and the more consecutive calculations there are the more inaccurate the outcome will be. It’s just the way decimal numbers work on computers. You’re fine with integer arithmetic (apart from over and underflow problems), but floating point numbers are inherently inaccurate.

1 Like
1 Like