^ vs exp for exponentiation

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.

1 Like

why doesn’t ^ lower to exp?

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

1 Like

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.

3 Likes