Skip to content

Compatibility for overriding cld/fld #34134

@sostock

Description

@sostock

The implementation on current master (see below) claims to provide compatibility for overriding cld/fld, but actually doesn’t (at least in the case of HalfIntegers.jl, which is currently broken on master for this reason).

julia/base/div.jl

Lines 223 to 233 in 8707744

# These are kept for compatibility with external packages overriding fld/cld.
# In 2.0, packages should extend div(a,b,r) instead, in which case, these can
# be removed.
fld(x::Real, y::Real) = div(promote(x,y)..., RoundDown)
cld(x::Real, y::Real) = div(promote(x,y)..., RoundUp)
fld(x::Signed, y::Unsigned) = div(x, y, RoundDown)
fld(x::Unsigned, y::Signed) = div(x, y, RoundDown)
cld(x::Signed, y::Unsigned) = div(x, y, RoundUp)
cld(x::Unsigned, y::Signed) = div(x, y, RoundUp)
fld(x::T, y::T) where {T<:Real} = throw(MethodError(div, (x, y, RoundDown)))
cld(x::T, y::T) where {T<:Real} = throw(MethodError(div, (x, y, RoundUp)))

HalfIntegers.jl defines fld(x::T, y::T) where T<:HalfInteger. Due to the changes on master, this method isn’t called anymore when fld is called with two different types of HalfIntegers. In order for the above code to fulfill its purpose, the first two and last two methods above could be replaced with

fld(x::Real, y::Real) = fld(promote(x,y)...)
cld(x::Real, y::Real) = cld(promote(x,y)...)
fld(x::T, y::T) where {T<:Real} = div(x, y, RoundDown)
cld(x::T, y::T) where {T<:Real} = div(x, y, RoundUp)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions