Equality test error

(Mesrop Andriasyan) #1

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.

(David Rutten) #2

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.

(Mesrop Andriasyan) #3

Thank you.

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

With the internalised point:

Equality test.gh (10.3 KB)

(David Rutten) #4

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.

(jesterKing) #5