Skip to content

Commit eccd25a

Browse files
committed
Revert "fix mod for mixes of Signed and Unsigned (#57853)"
This reverts commit 9b474fa.
1 parent 8063884 commit eccd25a

File tree

2 files changed

+2
-25
lines changed

2 files changed

+2
-25
lines changed

base/int.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,8 @@ function mod(x::T, y::T) where T<:Integer
286286
y == -1 && return T(0) # avoid potential overflow in fld
287287
return x - fld(x, y) * y
288288
end
289-
function mod(x::BitSigned, y::Unsigned)
290-
remval = rem(x, y) # correct iff remval>=0
291-
return unsigned(remval + (remval<zero(remval))*y)
292-
end
293-
function mod(x::Unsigned, y::Signed)
294-
remval = signed(rem(x, y)) #remval>0 so correct iff y>0 or remval==0
295-
return remval + (!iszero(remval) && y<zero(y))*y
296-
end
289+
mod(x::BitSigned, y::Unsigned) = rem(y + unsigned(rem(x, y)), y)
290+
mod(x::Unsigned, y::Signed) = rem(y + signed(rem(x, y)), y)
297291
mod(x::T, y::T) where {T<:Unsigned} = rem(x, y)
298292

299293
# Don't promote integers for div/rem/mod since there is no danger of overflow,

test/int.jl

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -358,23 +358,6 @@ end
358358
end
359359
end
360360
end
361-
# exhaustive UInt8/Int8 tests for mixed signedness
362-
for f in (mod, rem)
363-
for i in -128:127
364-
for j in 0:255
365-
if iszero(i)
366-
@test_throws DivideError f(UInt8(j), Int8(i))
367-
else
368-
@test f(UInt8(j), Int8(i)) == f(j, i)
369-
end
370-
if iszero(j)
371-
@test_throws DivideError f(Int8(i), UInt8(j))
372-
else
373-
@test f(Int8(i), UInt8(j)) == f(i,j)
374-
end
375-
end
376-
end
377-
end
378361
end
379362

380363
@testset "Underscores in big_str" begin

0 commit comments

Comments
 (0)