Performance of cld vs ceil

For floating-point arguments,

julia> x = 5.5; y = 2.2;

julia> @btime cld($(Ref(x))[], $(Ref(y))[])
  23.836 ns (0 allocations: 0 bytes)
3.0

julia> @btime ceil(($(Ref(x))[] / $(Ref(y))[]))
  2.682 ns (0 allocations: 0 bytes)
3.0

Why is cld so much slower than ceil?

It looks like we are calling the wrong method for it accidentally. We are currently calling cld(x::T, y::T) where T<:AbstractFloat in Base at float.jl:422, but we should be calling cld(a::T, b::T) where T<:Union{AbstractFloat, Integer} in Base at div.jl:269. I’m not sure what caused this.

Non-union argument is “more specific” than union argument? I think this should’ve errored ambigously.

1 Like

this isn’t an ambiguity error because the union is strictly less specific. what I meant is I’m not sure went we have the worse method defined at all.