Problem with trivial arithmetic

In my function “main” I have:
floor1 = floor(Int64, 4382/6)
println("floor1 = ", floor1)
Hfloor1 = 6floor1
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?

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

Please read PSA: make it easier to help you . Especially the first part will help you write your code in a way that is easier to understand

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

1 Like
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.

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

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

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