# Predicate for checking wider subtype of \`Integer\`

**URL:** <https://discourse.julialang.org/t/predicate-for-checking-wider-subtype-of-integer/7566>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 6, 2017, 12:47pm UTC](https://discourse.julialang.org/t/predicate-for-checking-wider-subtype-of-integer/7566 "2017-12-06T12:47:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 6, 2017, 12:47pm UTC](https://discourse.julialang.org/t/predicate-for-checking-wider-subtype-of-integer/7566/1 "2017-12-06T12:47:59Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [December 6, 2017, 1:08pm UTC](https://discourse.julialang.org/t/predicate-for-checking-wider-subtype-of-integer/7566/2 "2017-12-06T13:08:52Z")

</div>

Is this what you mean?

```julia
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

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 6, 2017, 1:18pm UTC](https://discourse.julialang.org/t/predicate-for-checking-wider-subtype-of-integer/7566/3 "2017-12-06T13:18:24Z")

</div>

Thanks! Perhaps

```julia
iswider(T,S) = S ≡ promote_type(T, S)

```

is even simpler and appears to work too.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [December 6, 2017, 1:20pm UTC](https://discourse.julialang.org/t/predicate-for-checking-wider-subtype-of-integer/7566/4 "2017-12-06T13:20:00Z")

</div>

Yup there is also that 😄
