# Why do simple arithmetics cause weird Precision bugs

**URL:** <https://discourse.julialang.org/t/why-do-simple-arithmetics-cause-weird-precision-bugs/119218>\
**Category:** General Usage\
**Created:** [September 9, 2024, 4:18pm UTC](https://discourse.julialang.org/t/why-do-simple-arithmetics-cause-weird-precision-bugs/119218 "2024-09-09T16:18:44Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [September 9, 2024, 4:26pm UTC](https://discourse.julialang.org/t/why-do-simple-arithmetics-cause-weird-precision-bugs/119218/2 "2024-09-09T16:26:41Z")

</div>

> [@PSA: floating-point arithmetic](https://discourse.julialang.org/t/psa-floating-point-arithmetic/8678):
>
> Sometimes people are surprised by the results of floating-point calculations such as julia\> 5/6 0.8333333333333334 # shouldn't the last digit be 3? julia\> 2.6 - 0.7 - 1.9 2.220446049250313e-16 # shouldn't the answer be 0? These are not bugs in Julia. They’re consequences of the IEEE-standard 64-bit binary representation of floating-point numbers that is burned into computer hardware, which Julia and many other languages use by default. Brief explanation You can t…

In short, `295.8` is not the number you think it is. It’s actually 295.80000000000001136868377216160297393798828125:

```julia-auto
julia> using Printf; @printf "%.60f" 295.8
295.800000000000011368683772161602973937988281250000000000000000

```

`295.8` is used to input (and output) that number because there’s no other floating point number closer to the exact 295.8 than that one. So then when you do maths with that number, you can get further roundings away from what you’d otherwise expect.

To make this even more tangible, you can see that if you subtract `295` from the above _true value_, the answer must be 0.80000000000001136868377216160297393798828125, or the nearest floating point number that rounds to it:

```Julia
julia> 295.8-295
0.8000000000000114

```

---

_[View the full topic](https://discourse.julialang.org/t/why-do-simple-arithmetics-cause-weird-precision-bugs/119218)._
