# Return type of powermod is always a Union?

**URL:** <https://discourse.julialang.org/t/return-type-of-powermod-is-always-a-union/93278>\
**Category:** General Usage\
**Tags:** type-stability\
**Created:** [January 20, 2023, 8:13pm UTC](https://discourse.julialang.org/t/return-type-of-powermod-is-always-a-union/93278 "2023-01-20T20:13:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gtgt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gtgt/32/46932_2.png) [@gtgt](https://discourse.julialang.org/u/gtgt)\
**Post date:** [January 20, 2023, 8:13pm UTC](https://discourse.julialang.org/t/return-type-of-powermod-is-always-a-union/93278/1 "2023-01-20T20:13:29Z")

</div>

Why is the return type of `powermod` always a `Union{Int64, Int128, BigInt}`? As a consequence the following simple code is type-unstable:

```julia
julia> function f(a, b, c)
          a = powermod(a, b, c)
          a % 2 - a
       end

julia> @code_warntype f(3, 4, 5)
MethodInstance for f(::Int64, ::Int64, ::Int64)
  from f(a, b, c) @ Main REPL[16]:1
Arguments
  #self#::Core.Const(f)
  a@_2::Int64
  b::Int64
  c::Int64
Locals
  a@_5::Union{Int128, Int64, BigInt}
Body::Any
1 ─ (a@_5 = a@_2)
│ (a@_5 = Main.powermod(a@_5::Int64, b, c))
│ %3 = (a@_5 % 2)::Union{Int128, Int64, BigInt}
│ %4 = (%3 - a@_5)::Any
└── return %4 

```

Is it to account for overflowing?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [January 20, 2023, 8:19pm UTC](https://discourse.julialang.org/t/return-type-of-powermod-is-always-a-union/93278/2 "2023-01-20T20:19:20Z")

</div>

This is on 1.10, right? Good catch. PR incoming.
