Calculating ULP distance between two floating point numbers (quickly)

Is using isapprox an option? You can give it an absolute or relative allowed difference.

In case it isn’t, the code from your link would look like this in julia:

function ulpsBetween(a::Float64, b::Float64)
    a == b && return 0
    isnan(a) || isnan(b) && return typemax(Int)
    isinf(a) || isinf(b) && return typemax(Int)
    
    a_int = reinterpret(Int64, a)
    b_int = reinterpret(Int64, b)

    (a_int < 0) != (b_int < 0) && return typemax(Int)

    return abs(a_int - b_int)
end

Still, the link discusses precisely why this sort of comparison usually isn’t a good idea (and isapprox is usually the best choice anyway). It’s implemented like this:

function isapprox(x::Number, y::Number;                                                                                          
                  atol::Real=0, rtol::Real=rtoldefault(x,y,atol),                                                                
                  nans::Bool=false, norm::Function=abs)                                                                          
    x == y || (isfinite(x) && isfinite(y) && norm(x-y) <= max(atol, rtol*max(norm(x), norm(y)))) || (nans && isnan(x) && isnan(y)
end                                                                                                                              

which you can find via @edit isapprox(0.5, 1.0) at base/floatfuncs.jl:360.