# \`Pow\` trait/raise to power operator

**URL:** <https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340>\
**Category:** language design\
**Created:** [August 8, 2025, 1:00pm UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340 "2025-08-08T13:00:03Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![VitWW](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/vitww/32/10822_2.png) [@VitWW](https://internals.rust-lang.org/u/VitWW)\
**Post date:** [August 9, 2025, 2:23am UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/21 "2025-08-09T02:23:34Z")

</div>

Then sorry, I misunderstood your position.

Rust Devs have very strict policy about which operators could be added to the language.

The reason must be very-very promising. And adding "logical xor" operator does not look promising at all. That was my point.

But adding powering operator could be promising because most languages, which inspires Rust has such operator. And such action as powering is common for most people who learn math at school.

---

<div class="post-metadata">

**Author:** ![jdahlstrom](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jdahlstrom/32/3351_2.png) [@jdahlstrom](https://internals.rust-lang.org/u/jdahlstrom)\
**Post date:** [August 9, 2025, 11:35am UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/22 "2025-08-09T11:35:15Z")

</div>

Another (slight) advantage of a dedicated operator would be not having to care about `powi` versus `powf`.

---

<div class="post-metadata">

**Author:** ![oakchris1955](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/oakchris1955/32/13480_2.png) [@oakchris1955](https://internals.rust-lang.org/u/oakchris1955)\
**Post date:** [August 9, 2025, 1:17pm UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/23 "2025-08-09T13:17:54Z")

</div>

I stand on my original proposal for using `**` as an operator. I don't think `^^` is suitable for a power operator, since it resembles Knuth's up arrow notation (`↑↑`). My proposal is to use the `**` operator, for the reasons mentioned above by me and others, most notable the fact that programming languages that have a power operator tend to use `**` and that it would be good to have a dedicated operator for exponentiation.

Some people have expressed their concerns that ` **` could cause issues with code where that syntax exists already, with the second `*` dereferencing an integer reference and the first one performing a multiplication. However, this change, although breaking, I don't believe it is a major one and could occur over the course of a Rust edition. In that case, if `** ` were to take precedence over both the `*` deref and the `*` multiplication operator, migration could be as easy as [that](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=dd0e6ea4c5f5dcda292a5b965319d9dd). Of course, that is just one possible solution to the problem, but what I wanna say is that there are ways around it.

---

<div class="post-metadata">

**Author:** ![DasLixou](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/daslixou/32/12132_2.png) [@DasLixou](https://internals.rust-lang.org/u/DasLixou)\
**Post date:** [August 10, 2025, 11:32am UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/24 "2025-08-10T11:32:43Z")

</div>

We could also just make a `Pow<Exp>` trait _without_ an operator. Would still help with type inference and having a method for all number types

---

<div class="post-metadata">

**Author:** ![oakchris1955](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/oakchris1955/32/13480_2.png) [@oakchris1955](https://internals.rust-lang.org/u/oakchris1955)\
**Post date:** [August 10, 2025, 11:39am UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/25 "2025-08-10T11:39:35Z")

</div>

Choosing an operator could take some time (what symbols to use, backwards compatibility for cases such as [this](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/2), but putting all the `pow` methods in their own trait would probably be a faster procedure. What would be the best way to suggest this change? A separate post here on Rust Internals? A RFC?

---

<div class="post-metadata">

**Author:** ![DasLixou](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/daslixou/32/12132_2.png) [@DasLixou](https://internals.rust-lang.org/u/DasLixou)\
**Post date:** [August 10, 2025, 11:47am UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/26 "2025-08-10T11:47:50Z")

</div>

The normal way would be to [file an ACP](https://std-dev-guide.rust-lang.org/development/feature-lifecycle.html)

---

<div class="post-metadata">

**Author:** ![DasLixou](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/daslixou/32/12132_2.png) [@DasLixou](https://internals.rust-lang.org/u/DasLixou)\
**Post date:** [August 10, 2025, 11:49am UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/27 "2025-08-10T11:49:51Z")

</div>

Maybe try to make an impl of the trait on your own first so you can directly show the difficulty and behavior when proposing it

---

<div class="post-metadata">

**Author:** ![tczajka](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tczajka/32/8923_2.png) [@tczajka](https://internals.rust-lang.org/u/tczajka)\
**Post date:** [August 10, 2025, 11:57pm UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/28 "2025-08-10T23:57:50Z")

</div>

> [@jdahlstrom](#):
>
> Another (slight) advantage of a dedicated operator would be not having to care about `powi` versus `powf`.

A trait would do this regardless of an operator.

Optimally a lot of methods that exist for various numeric types (such as `trailing_zeros`) would be parts of traits, so that they can be used directly in generic code.

---

<div class="post-metadata">

**Author:** ![rne](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/rne/32/12362_2.png) [@rne](https://internals.rust-lang.org/u/rne)\
**Post date:** [August 18, 2025, 11:57am UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/29 "2025-08-18T11:57:16Z")

</div>

We already have all of this, just not in `std`.

> **[Pow in num\_traits::pow - Rust](https://docs.rs/num-traits/latest/num_traits/pow/trait.Pow.html)**
>
> Binary operator for raising a value to a power.

> **[PrimInt in num\_traits::int - Rust](https://docs.rs/num-traits/latest/num_traits/int/trait.PrimInt.html#tymethod.trailing_zeros)**
>
> Generic trait for primitive integers.

---

<div class="post-metadata">

**Author:** ![oakchris1955](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/oakchris1955/32/13480_2.png) [@oakchris1955](https://internals.rust-lang.org/u/oakchris1955)\
**Post date:** [August 19, 2025, 1:03pm UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/30 "2025-08-19T13:03:39Z")

</div>

Adding the `Pow` trait in the Rust Core Library could pave the way for an exponentiation operator.

---

<div class="post-metadata">

**Author:** ![R081n](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/r081n/32/12214_2.png) [@R081n](https://internals.rust-lang.org/u/R081n)\
**Post date:** [August 19, 2025, 6:36pm UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/31 "2025-08-19T18:36:16Z")

</div>

I feel like this would be very dangerous. `pow` itself is a very niche function. So i would assume that a `**` found in a file is more likely actually meant do be a dereference and multiply, but the author forgot that `cargo fmt` no longer inserts the missing space.

So we'd need to have a lint `use_of_pow_op`. Wich would be used in more crates than the `pow` operator

Also can anyone actuality give an example of a language with the `**` operatior that also has `*` as a dereference operator.

Neither JavaScript, Python nor Haskell have a dereference operator.

I just thought about `cargo fmt` again. We now have format editions, but these must be manually chosen when using `rustfmt` directly. This would mean that accidentally using the wrong style edition when formatting would change the semantics of the program because `a**b` is replaced with `a * *b` in the current edition .

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [August 19, 2025, 7:04pm UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/32 "2025-08-19T19:04:19Z")

</div>

> [@R081n](#):
>
> Neither JavaScript, Python nor Haskell have a dereference operator.

Python does have` f(*args, **kwargs)`. But I believe these _only_ work inside function calls as unary operators.

---

<div class="post-metadata">

**Author:** ![cuviper](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cuviper/32/1897_2.png) [@cuviper](https://internals.rust-lang.org/u/cuviper)\
**Post date:** [August 19, 2025, 7:31pm UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/33 "2025-08-19T19:31:42Z")

</div>

Python `*expr` is allowed in [expression lists](https://docs.python.org/3/reference/expressions.html#expression-lists), including set, list, and tuple constructors, and `**expr` is also allowed in [dictionaries](https://docs.python.org/3/reference/expressions.html#dictionary-displays). These can't be confused for a binary op though.

---

<div class="post-metadata">

**Author:** ![VitWW](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/vitww/32/10822_2.png) [@VitWW](https://internals.rust-lang.org/u/VitWW)\
**Post date:** [August 20, 2025, 1:24am UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/34 "2025-08-20T01:24:56Z")

</div>

> [@R081n](#):
>
> I feel like this would be very dangerous. `pow` itself is a very niche function. So i would assume that a `**` found in a file is more likely actually meant do be a dereference and multiply

Hopefully, `**` is not the only option. We could define `^^` for example for powering. It looks very human-friendly, a lot of people write `2^8` or `3^5` to represent powering.

And `2 ^^ 8` or `3 ^^ 5` looks as good as expected.

And hopefully, wrong writing expression `2 ^ ^ 8` always call the error during compilation, because `xor` of `xor` has no meaning.

---

<div class="post-metadata">

**Author:** ![VitWW](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/vitww/32/10822_2.png) [@VitWW](https://internals.rust-lang.org/u/VitWW)\
**Post date:** [August 20, 2025, 3:40am UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/35 "2025-08-20T03:40:44Z")

</div>

I found an example of using `^^` in popular languages:

For example, Haskell has 2 similar functions-operators in `Prelude`:

```haskell
-- raise a number to a non-negative integral power
(^) :: (Num a, Integral b) => a -> b -> a -- infixr 8

-- raise a number to an integral power
(^^) :: (Fractional a, Integral b) => a -> b -> a -- infixr 8

```

So, it is not so "esoteric" to use `^^` for powering.

---

<div class="post-metadata">

**Author:** ![jdahlstrom](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jdahlstrom/32/3351_2.png) [@jdahlstrom](https://internals.rust-lang.org/u/jdahlstrom)\
**Post date:** [August 20, 2025, 7:06am UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/36 "2025-08-20T07:06:15Z")

</div>

As mentioned in another comment, ^^ looks a bit too much like tetration (as in, repeated exponentiation, using Knuth’s arrow notation). Though I guess in practice I doubt many people would assume there’s an operator for something as obscure as that.

---

<div class="post-metadata">

**Author:** ![oakchris1955](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/oakchris1955/32/13480_2.png) [@oakchris1955](https://internals.rust-lang.org/u/oakchris1955)\
**Post date:** [August 20, 2025, 7:37am UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/37 "2025-08-20T07:37:42Z")

</div>

While I believe that `^^` might remind a couple of people of tetration, I honestly doubt there is even a single program or algorithm out there that actively uses this kind of operation. I still root for `**`, but considering the potential issues eith it, I believe `^^` would be a good alternative.

---

<div class="post-metadata">

**Author:** ![VitWW](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/vitww/32/10822_2.png) [@VitWW](https://internals.rust-lang.org/u/VitWW)\
**Post date:** [August 20, 2025, 11:15am UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/38 "2025-08-20T11:15:12Z")

</div>

95% of people who use Rust don't know about "tetration" and how it looks. And by the way, it looks absolutely differently: `↑↑`, not at all close to `^^`.

And even who knew about such operation, they 99.999999% never ever use it in Rust.

So, why are we talking about "tetration"?

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [August 20, 2025, 2:39pm UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/39 "2025-08-20T14:39:27Z")

</div>

> **[Tetration | Notation](https://en.wikipedia.org/wiki/Tetration#Notation)**
>
> There are many different notation styles that can be used to express tetration. Some notations can also be used to describe other hyperoperations, while some are limited to tetration and have no immediate extension.

> Since the up-arrow is used identically to the caret (`^`), tetration may be written as (`^^`); convenient for ASCII.

Doesn't make it the _only_ interpretation, but it's _an_ interpretation.

---

<div class="post-metadata">

**Author:** ![oakchris1955](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/oakchris1955/32/13480_2.png) [@oakchris1955](https://internals.rust-lang.org/u/oakchris1955)\
**Post date:** [August 20, 2025, 2:59pm UTC](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340/40 "2025-08-20T14:59:50Z")

</div>

Tetration is a pretty uncommon mathematical operation. [Wikipedia](https://en.wikipedia.org/w/index.php?title=Tetration&oldid=1298774633#Applications) lists only 1 application, while in a [Quora](https://www.quora.com/What-are-the-real-life-applications-of-tetration) thread, one of the answers suggests it doesn't have an application even in theoretical mathematics. Apart from that, I would be surprised if there is a (non-esoteric) programming language out there that has a tetration operator. Nevertheless, if `^^` can't be used, we could resort to `**`, which unfortunately suffers from the problems previously discussed.

[Previous page](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340.md?page=1)

[Next page](https://internals.rust-lang.org/t/pow-trait-raise-to-power-operator/23340.md?page=3)
