Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function invmod(n::Integer, m::Integer)
g, x, y = gcdx(n, m)
g != 1 && throw(DomainError((n, m), LazyString("Greatest common divisor is ", g, ".")))
# Note that m might be negative here.
if n isa Unsigned && hastypemax(typeof(n)) && x > typemax(n)>>1
if promote_type(typeof(n), typeof(m))<:Unsigned && hastypemax(typeof(n)) && x > typemax(n)>>1
# x might have wrapped if it would have been negative
# adding back m forces a correction
x += m
Expand Down
4 changes: 4 additions & 0 deletions test/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ end
@test invmod(T(3), T(124))::T == 83
end

for T in (Int8, Int16, Int32, Int64, Int128)
@test invmod(T(3), unsigned(T)(124)) == 83
end

for T in (Int8, UInt8)
for x in typemin(T):typemax(T)
for m in typemin(T):typemax(T)
Expand Down