Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 x isa Unsigned && hastypemax(typeof(x)) && x > typemax(x)>>1
# x might have wrapped if it would have been negative
# adding back m forces a correction
x += m
Expand Down
7 changes: 7 additions & 0 deletions test/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ 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 issue 58010
@test invmod(UInt8(3), UInt16(50000)) === 0x411b

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