Should exp2 be faster than exp?
There are a number of platforms that don't take much care with their math library on which exp2(x)
is simply implemented as exp(x * log(2))
or vice-versa. These implementations do not deliver good accuracy (or especially good performance), but they are fairly common. On platforms that do this, one function is exactly as costly as the other but for the cost of an extra multiply, and whichever gets the extra multiply will be the slower of the two.
On platforms that aggressively tune the math library and try to deliver good accuracy, the two functions are very similar in performance. Generating the exponent of the result is easier with exp2
, but getting a high-accuracy significand can require slightly more work; the two factors roughly even out to the point that performance is usually equivalent within a factor of 10-15%. Speaking very broadly, exp2
is usually the faster of the two.