Skip to content

Commit 34ca8ea

Browse files
committed
MethodError for missing div fallback
also a better compatibility fallback to two-argument div for packages that haven't upgraded yet. Fixes #33651
1 parent dbad68d commit 34ca8ea

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

base/div.jl

+9-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,15 @@ fld(x::T, y::T) where {T<:Real} = throw(MethodError(div, (x, y, RoundDown)))
231231
cld(x::T, y::T) where {T<:Real} = throw(MethodError(div, (x, y, RoundUp)))
232232

233233
# Promotion
234-
div(x::Real, y::Real, r::RoundingMode) = div(promote(x, y)..., r)
234+
function div(x::Real, y::Real, r::RoundingMode)
235+
typeof(x) === typeof(y) && throw(MethodError(div, (x, y, r)))
236+
if r == RoundToZero
237+
# For compat. Remove in 2.0.
238+
div(promote(x, y)...)
239+
else
240+
div(promote(x, y)..., r)
241+
end
242+
end
235243

236244
# Integers
237245
# fld(x,y) == div(x,y) - ((x>=0) != (y>=0) && rem(x,y) != 0 ? 1 : 0)

0 commit comments

Comments
 (0)