# There is a possibility to DivideError without a denominator value of 0

I’m sorry to ask this without specific cases(i can’t find that), but our team guess that the following code raise the DivideError.

    while y != zero(R)
q = div(x, y)
x, y = y, x - y * q
s0, s1 = s1, s0 - q * s1
t0, t1 = t1, t0 - q * t1
end


The while guarantees that y is nonzero hence div must work properly, but error occurs. Anybody has a clue?

ps. One coworker guessed that the large integers may be a suspect. Is it possible? If then, how we overcome this issue? BigInt?

ps2. I just found a case!

julia> div(-9223372036854775808,-1)
ERROR: LoadError: DivideError: integer division error
Stacktrace:
[1] div(x::Int64, y::Int64)
@ Base .\int.jl:284


Is this overflow issue?

julia> typemax(Int64)
9223372036854775807

julia> -9223372036854775808
-9223372036854775808


What is R? What type is it?

Probably, yeah. Note that the max and min values of a signed integer differ by one:

julia> typemin(Int8)
-128

julia> typemax(Int8)
127


due to the two’s complement representation.

1 Like