# Problem with trivial arithmetic

**URL:** <https://discourse.julialang.org/t/problem-with-trivial-arithmetic/52899>\
**Category:** New to Julia\
**Created:** [January 5, 2021, 8:02pm UTC](https://discourse.julialang.org/t/problem-with-trivial-arithmetic/52899 "2021-01-05T20:02:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjdegruijter](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@jjdegruijter](https://discourse.julialang.org/u/jjdegruijter)\
**Post date:** [January 5, 2021, 8:02pm UTC](https://discourse.julialang.org/t/problem-with-trivial-arithmetic/52899/1 "2021-01-05T20:02:11Z")

</div>

In my function “main” I have:  
floor1 = floor(Int64, 4382/6)  
println("floor1 = ", floor1)  
Hfloor1 = 6_floor1  
println("Hfloor1 = ", Hfloor1)  
missing1 = 4382 - Hfloor1  
println("missing1 = ", missing1)  
Hfloor2 = -6_floor1  
println("Hfloor2 = ", Hfloor2)  
missing2 = 4382 + Hfloor2  
println("missing2 = ", missing2)

The result is:  
julia\> include(“main”)  
floor1 = 730  
Hfloor1 = 4380  
missing1 = 0.03  
Hfloor2 = -4380  
missing2 = 2

Comment: missing2 is correct, but the value 0.03 for missing1 is a parameter mentioned somewhere else in “main”.  
Question: why went missing1 astray?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [January 5, 2021, 8:03pm UTC](https://discourse.julialang.org/t/problem-with-trivial-arithmetic/52899/2 "2021-01-05T20:03:19Z")

</div>

please format your code. And what aspect of `missing1` is unexpected? You probably have some code, please try in a new session.

---

<div class="post-metadata">

**Author:** ![josuagrw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josuagrw/32/1015_2.png) [@josuagrw](https://discourse.julialang.org/u/josuagrw)\
**Post date:** [January 5, 2021, 8:13pm UTC](https://discourse.julialang.org/t/problem-with-trivial-arithmetic/52899/3 "2021-01-05T20:13:26Z")

</div>

Please read [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757) . Especially the first part will help you write your code in a way that is easier to understand

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 5, 2021, 10:14pm UTC](https://discourse.julialang.org/t/problem-with-trivial-arithmetic/52899/4 "2021-01-05T22:14:26Z")

</div>

> [@jjdegruijter](#):
>
> floor1 = floor(Int64, 4382/6)  
> println("floor1 = ", floor1)  
> Hfloor1 = 6floor1  
> println("Hfloor1 = ", Hfloor1)  
> missing1 = 4382 - Hfloor1  
> println("missing1 = ", missing1)

Isn’t it better to use `div` and `rem` (or `divrem`)? No reason to use floating point division here.

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [January 6, 2021, 1:31am UTC](https://discourse.julialang.org/t/problem-with-trivial-arithmetic/52899/5 "2021-01-06T01:31:00Z")

</div>

```julia
julia> floor1 = floor(Int64, 4382/6)
730

julia> println("floor1 = ", floor1)
floor1 = 730

julia> Hfloor1 = 6floor1
4380

julia> println("Hfloor1 = ", Hfloor1)
Hfloor1 = 4380

julia> missing1 = 4382 - Hfloor1
2

julia> println("missing1 = ", missing1)
missing1 = 2

```

I ran your code, there is nothing wrong with it.

What is wrong is your **expectation** that missing1 should be ZERO. Please tell us why you think that missing1 should be ZERO.

---

<div class="post-metadata">

**Author:** ![jjdegruijter](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@jjdegruijter](https://discourse.julialang.org/u/jjdegruijter)\
**Post date:** [January 6, 2021, 6:51am UTC](https://discourse.julialang.org/t/problem-with-trivial-arithmetic/52899/6 "2021-01-06T06:51:24Z")

</div>

I didn’t expect zero as result for missing1. The correct answer is of course 2.  
The problem is that, when I run this as part of a code, I get 0.03.  
I used this as just an example. I could have given other examples.

I’ve written Julia code for many years, version 0.5, 0.6 and 1.0. These problems ocurred only after I upgraded to version 1.5. So I guess there is something wrong with how I upgraded.  
Sorry if I gave this issue a misleading title

---

<div class="post-metadata">

**Author:** ![aquarelle332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarelle332/32/20816_2.png) [@aquarelle332](https://discourse.julialang.org/u/aquarelle332)\
**Post date:** [January 6, 2021, 9:48am UTC](https://discourse.julialang.org/t/problem-with-trivial-arithmetic/52899/7 "2021-01-06T09:48:30Z")

</div>

I also ran your code (julia-1.5.3; VSCodium) ==\> missing1 = 2 (of course)

Like jling I wonder if a new session would not solve the problem. I don’t think it has anything to do with version 1.5.x.

If a new session fails to solve the problem,

- did you used some aliasing involving missing1?

- if it is not the case, can you tell us what you made during the update (redefining $PATH, cleaning old version(s), etc.)?

---

<div class="post-metadata">

**Author:** ![jjdegruijter](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@jjdegruijter](https://discourse.julialang.org/u/jjdegruijter)\
**Post date:** [January 6, 2021, 2:32pm UTC](https://discourse.julialang.org/t/problem-with-trivial-arithmetic/52899/8 "2021-01-06T14:32:43Z")

</div>

You were right! Starting a new session solved the problem.  
THANKS A LOT!
