# Strange arithmetic behaviour using structs

**URL:** <https://discourse.julialang.org/t/strange-arithmetic-behaviour-using-structs/135778>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [February 22, 2026, 5:54pm UTC](https://discourse.julialang.org/t/strange-arithmetic-behaviour-using-structs/135778 "2026-02-22T17:54:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Utz78](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/utz78/32/220917_2.png) [@Utz78](https://discourse.julialang.org/u/Utz78)\
**Post date:** [February 22, 2026, 5:54pm UTC](https://discourse.julialang.org/t/strange-arithmetic-behaviour-using-structs/135778/1 "2026-02-22T17:54:17Z")

</div>

I have noticed a strange behaviour when using structs in a simple equation. When I use structs the results of the calculations are wrong, and I cannot really understand why. I have made a minimal example that demonstrates the issue:

```julia-auto
struct Env
    L
end

env = Env(2)

t = 4

println("t-env.L+1: ", t-env.L+1)
println("t-(env.L+1): ", t-(env.L+1))

```

The code above results in the following output:  
t-env.L+1: 3  
t-(env.L+1): 1

Any clues why this is the case? is it a bug or a feature I just do not understand?

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [February 22, 2026, 5:58pm UTC](https://discourse.julialang.org/t/strange-arithmetic-behaviour-using-structs/135778/2 "2026-02-22T17:58:03Z")

</div>

The fact there are structs is irrelevant. `4-2+1` is `(4-2)+1` which is `3`, and `4-(2+1)` is `1`.

---

<div class="post-metadata">

**Author:** ![Utz78](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/utz78/32/220917_2.png) [@Utz78](https://discourse.julialang.org/u/Utz78)\
**Post date:** [February 22, 2026, 6:04pm UTC](https://discourse.julialang.org/t/strange-arithmetic-behaviour-using-structs/135778/3 "2026-02-22T18:04:22Z")

</div>

of course…I am such an idiot…I guess I worked too much and my brain is no longer working
