# Simple math operation failing

**URL:** <https://forum.dynamobim.com/t/simple-math-operation-failing/72084>\
**Category:** DesignScript\
**Tags:** mathematica\
**Created:** [January 7, 2022, 9:21pm UTC](https://forum.dynamobim.com/t/simple-math-operation-failing/72084 "2022-01-07T21:21:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubenbosetti](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@rubenbosetti](https://forum.dynamobim.com/u/rubenbosetti)\
**Post date:** [January 7, 2022, 9:21pm UTC](https://forum.dynamobim.com/t/simple-math-operation-failing/72084/1 "2022-01-07T21:21:53Z")

</div>

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))

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/8/08216c57572a7459d0b3b9faa2487b0434de62da.png)

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](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/f/0f6d4882bf81deee93c3cbe60fd1256df4fc2e42.png)

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?

---

<div class="post-metadata">

**Author:** ![Marcel\_Rijsmus](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/marcel_rijsmus/32/8539_2.png) [@Marcel\_Rijsmus](https://forum.dynamobim.com/u/Marcel_Rijsmus)\
**Post date:** [January 7, 2022, 9:39pm UTC](https://forum.dynamobim.com/t/simple-math-operation-failing/72084/2 "2022-01-07T21:39:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rubenbosetti](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@rubenbosetti](https://forum.dynamobim.com/u/rubenbosetti)\
**Post date:** [January 7, 2022, 9:56pm UTC](https://forum.dynamobim.com/t/simple-math-operation-failing/72084/3 "2022-01-07T21:56:43Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [January 7, 2022, 10:10pm UTC](https://forum.dynamobim.com/t/simple-math-operation-failing/72084/4 "2022-01-07T22:10:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [January 8, 2022, 3:14am UTC](https://forum.dynamobim.com/t/simple-math-operation-failing/72084/5 "2022-01-08T03:14:34Z")

</div>

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](https://stackoverflow.com/questions/2100490/floating-point-inaccuracy-examples)

---

<div class="post-metadata">

**Author:** ![mzjensen](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@mzjensen](https://forum.dynamobim.com/u/mzjensen)\
**Post date:** [January 8, 2022, 4:43pm UTC](https://forum.dynamobim.com/t/simple-math-operation-failing/72084/6 "2022-01-08T16:43:14Z")

</div>

Similar post here.

> [@Wrong calculation lot's of digits](https://forum.dynamobim.com/t/wrong-calculation-lots-of-digits/64833/4):
>
> I don’t think it’s wrong. It has to do with the way that double-precision floating point numbers work. This isn’t unique to Dynamo. [https://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/](https://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/) So basically, if you need precision out to the 16th decimal place, don’t use a double. Or just round it off slight_smile
