Skip to content

Commit bcb5605

Browse files
committed
Bugfixes
1 parent 14c2683 commit bcb5605

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

base/div.jl

+13
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,21 @@ end
202202
# generic signature also
203203
div(a::T, b::T, ::typeof(RoundToZero)) where {T<:Union{BitSigned, BitUnsigned64}} = div(a, b)
204204
div(a::Bool, b::Bool, r::RoundingMode) = div(a, b)
205+
# Prevent ambiguities
206+
for rm in (RoundUp, RoundDown, RoundToZero)
207+
@eval div(a::Bool, b::Bool, r::$(typeof(rm))) = div(a, b)
208+
end
209+
function div(x::Bool, y::Bool, rnd::Union{typeof(RoundNearest),
210+
typeof(RoundNearestTiesAway),
211+
typeof(RoundNearestTiesUp)})
212+
div(x, y)
213+
end
205214
fld(a::T, b::T) where {T<:Union{Integer,AbstractFloat}} = div(a, b, RoundDown)
206215
cld(a::T, b::T) where {T<:Union{Integer,AbstractFloat}} = div(a, b, RoundUp)
216+
div(a::Int128, b::Int128, ::typeof(RoundToZero)) = div(a, b)
217+
div(a::UInt128, b::UInt128, ::typeof(RoundToZero)) = div(a, b)
218+
rem(a::Int128, b::Int128, ::typeof(RoundToZero)) = rem(a, b)
219+
rem(a::UInt128, b::UInt128, ::typeof(RoundToZero)) = rem(a, b)
207220

208221
# These are kept for compatibility with external packages overriding fld/cld.
209222
# In 2.0, packages should extend div(a,b,r) instead, in which case, these can

base/int.jl

+11
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ div(x::Unsigned, y::BitSigned) = unsigned(flipsign(signed(div(x, unsigned(abs(y)
175175
rem(x::BitSigned, y::Unsigned) = flipsign(signed(rem(unsigned(abs(x)), y)), x)
176176
rem(x::Unsigned, y::BitSigned) = rem(x, unsigned(abs(y)))
177177

178+
function divrem(x::BitSigned, y::Unsigned)
179+
q, r = divrem(unsigned(abs(x)), y)
180+
flipsign(signed(q), x), flipsign(signed(r), x)
181+
end
182+
183+
function divrem(x::Unsigned, y::BitSigned)
184+
q, r = divrem(x, unsigned(abs(y)))
185+
unsigned(flipsign(signed(q), y)), r
186+
end
187+
188+
178189
"""
179190
mod(x, y)
180191
rem(x, y, RoundDown)

0 commit comments

Comments
 (0)