# ^ vs exp for exponentiation

**URL:** <https://discourse.julialang.org/t/vs-exp-for-exponentiation/69437>\
**Category:** Performance\
**Tags:** math\
**Created:** [October 8, 2021, 1:39pm UTC](https://discourse.julialang.org/t/vs-exp-for-exponentiation/69437 "2021-10-08T13:39:17Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [October 8, 2021, 1:39pm UTC](https://discourse.julialang.org/t/vs-exp-for-exponentiation/69437/1 "2021-10-08T13:39:17Z")

</div>

One last thing to note: If you care about performance, don’t use `^` whenever possible. `exp` (or `exp2`/`exp10`) will be 5x to 30x faster.

---

<div class="post-metadata">

**Author:** ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)\
**Post date:** [October 8, 2021, 2:18pm UTC](https://discourse.julialang.org/t/vs-exp-for-exponentiation/69437/2 "2021-10-08T14:18:38Z")

</div>

why doesn’t `^` lower to exp?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 8, 2021, 2:27pm UTC](https://discourse.julialang.org/t/vs-exp-for-exponentiation/69437/3 "2021-10-08T14:27:33Z")

</div>

it does, well, not “lowered to”, but calls `exp`, for `\euler ^ something`

---

<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:** [October 8, 2021, 2:30pm UTC](https://discourse.julialang.org/t/vs-exp-for-exponentiation/69437/4 "2021-10-08T14:30:38Z")

</div>

TLDR is that `exp` and friends work by reducing their argument to a small range and approximating the function over that range with a hard-coded polynomial (think Taylor polynomial. That’s wrong, but a usefully wrong model). When you have something like `Float64^Float64`, you either have implement it as `x^y=exp(y*log(x))`, where `log` and `exp` have to be special versions that return answers with higher precision than the datatype to retain accuracy.
