# Overflow issue?

**URL:** <https://discourse.julialang.org/t/overflow-issue/124009>\
**Category:** New to Julia\
**Tags:** question, float\
**Created:** [December 20, 2024, 9:13am UTC](https://discourse.julialang.org/t/overflow-issue/124009 "2024-12-20T09:13:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [December 20, 2024, 9:13am UTC](https://discourse.julialang.org/t/overflow-issue/124009/1 "2024-12-20T09:13:45Z")

</div>

Hello everyone,

Is this a bug ? Why is it false for some specific numbers while true for others?

```julia
julia> 3 * 1e-5 * 1e5 == 3.0
false

julia> 5 * 1e-5 * 1e5 == 5.0
true

julia> 6 * 1e-5 * 1e5 == 6.0
false

julia> 7 * 1e-5 * 1e5 == 7.0
false

julia> 8 * 1e-5 * 1e5 == 8.0
true

```

---

<div class="post-metadata">

**Author:** ![roflmaostc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roflmaostc/32/30123_2.png) [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Post date:** [December 20, 2024, 9:18am UTC](https://discourse.julialang.org/t/overflow-issue/124009/2 "2024-12-20T09:18:07Z")

</div>

It’s merely a precision issue of floating numbers. Overflow does not occur here.  
The reason is, `6e-5` cannot be exactly represented by floating point numbers.

Also, unless really intended, it’s better to approximately compare floating point numbers:

```julia
julia> 6*1e-5
6.000000000000001e-5

julia> 6 * 1e-5 * 1e5 ≈ 6.0
true

```

EDIT: Similar also in Python or any otherIEEE Standard for Floating-Point Arithmetic:

```python
>>> 6 * 1e-5 * 1e5
6.000000000000001

```

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [December 20, 2024, 3:53pm UTC](https://discourse.julialang.org/t/overflow-issue/124009/3 "2024-12-20T15:53:52Z")

</div>

Even ignoring the leading terms, there is no guarantee that `1/x * x == 1`. `49e0` and `41f0` are such numbers. For example,

```julia-repl
julia> 49e0 / 49e0 # float division by oneself is always 1 (except for 0 and !isfinite)
1.0

julia> 49e0 * (1/49e0) # invert-and-multiply is not the same because the 2 operations accumulate error
0.9999999999999999

julia> 49e0 / complex(49e0) # this issue leads to this annoying quirk for Complex
0.9999999999999999 - 0.0im

julia> using LinearAlgebra

julia> normalize([49e0]) # another invert-and-multiply example
1-element Vector{Float64}:
 0.9999999999999999

```

It’s one of my pet projects to change complex division example to equal 1, but it’s challenging to do it without noticeably degrading performance. I kept getting close and then spilling registers. I’m hoping that better compiler optimization might eventually squeeze it in, but maybe it’s just barely out of reach for current architectures.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [December 20, 2024, 4:40pm UTC](https://discourse.julialang.org/t/overflow-issue/124009/4 "2024-12-20T16:40:48Z")

</div>

you should see if it’s fast on arm. you get twice as many registers there
