# Why doesn't \`^\` promote its arguments?

**URL:** <https://discourse.julialang.org/t/why-doesnt-promote-its-arguments/76444>\
**Category:** General Usage\
**Created:** [February 14, 2022, 4:29pm UTC](https://discourse.julialang.org/t/why-doesnt-promote-its-arguments/76444 "2022-02-14T16:29:00Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![Federico\_Marotta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/federico_marotta/32/33810_2.png) [@Federico\_Marotta](https://discourse.julialang.org/u/Federico_Marotta)\
**Post date:** [February 15, 2022, 1:30pm UTC](https://discourse.julialang.org/t/why-doesnt-promote-its-arguments/76444/16 "2022-02-15T13:30:16Z")

</div>

> [@Palli](#):
>
> No, `-` , `*` will always give integers for integer input, while `/` will always give Float64, and when b in a^b is negative (and since it is special-cased for the sign, I’m guessing it was chosen to ignore type of b when positive, unless when its BigInt). In both cases Rational is arguable more correct, but slower, so tat was decided.

You are right, `/` will always give `Float64`.

Regarding the discussions about [integer exponents](https://discourse.julialang.org/t/julia-messes-up-integer-exponents/20773) and [integer overflow](https://discourse.julialang.org/t/discussion-about-integer-overflow/69627), note that I don’t have a problem with unchecked integer overflow. `2^63` equals `-9223372036854775808`, which is totally acceptable and unsurprising, I’m just saying that `Int8(2)^63` should give the same result, because one of the arguments of `^`, namely `63`, is of type `Int64` (at least on my system). On the other hand, `Int8(2)^Int8(63)` should give `0`.

I also think that my discussion does not involve `Floats` at all. It seems that powers with float arguments are handled by a different function:

```julia
julia> @which 3.0^2
^(x::Float64, y::Integer) in Base.Math at math.jl:922

```

whereas

```julia
julia> @which 3^2
^(x::T, p::T) where T<:Integer in Base at intfuncs.jl:290

```

So, by changing the `power_by_squaring()` function, there wouldn’t be a performance decrease stemming from promoting integer exponents to floats.

Anyway, as @stephancb said, changing `power_by_squaring()` would be breaking, at this point. I guess I’ll just note down this behaviour and be careful with my code 🙂

---

_[View the full topic](https://discourse.julialang.org/t/why-doesnt-promote-its-arguments/76444)._
