If T <: Integer and S <: Integer, how can I check that S is (weakly) wider than T?
Comparing typemax and typemin does not work because of BigInt. I could special-case BigInt, but then I would miss similar user-defined types (a theoretical concern ATM).
Is this what you mean?
julia> <=(T,S) = begin; lt_eq = T === S; while !lt_eq && T != widen(T); T = widen(T); lt_eq = T === S; end; lt_eq; end
<= (generic function with 1 method)
julia> <=(Int,BigInt)
true
julia> <=(BigInt,BigInt)
true
julia> <=(BigInt,Int)
false
Thanks! Perhaps
iswider(T,S) = S ≡ promote_type(T, S)
is even simpler and appears to work too.
1 Like