Simple math operation failing

Here’s a strange math issue:
This specifical and simple math operation is giving me an incorrect, though very little result
0.85 - (3.88 - (0.23+0+2.57+0.23))

If you’re wandering why these numbers… it’s of course part of a debug process. These are numbers from different variables. I thought I was getting a bad result from a geometric function and this was cascading down till here, but when I manually wrote down the numbers and performed the operation it was still incorrect.

I can also simplify it till this point and it’s still giving me this incorrect result:
image

But if I just write 0.85 - 0.85 the result is 0.

Any idea why is this possible?
Has anyone got this problem too?

Maybe change units
If a number is divided and the outcome is very, very small, this happens

That’s what I was thinking before manually inputing the numbers, but now they’re just sums and subtractions and the error is still there…

As Marcel said, this is pretty common when dealing with very small numbers or a value that has a different level of precision than Dynamo. Just round to a reasonable precision and they should clear up.

Welcome to the world of floating point arithmetic issues.

You are basically coming up against the ‘after adding a teaspoon of water into a swimming pool you still have a swimming pool’s worth of water’ example given here: Floating point inaccuracy examples - Stack Overflow

2 Likes

Similar post here.

1 Like