Since this is CS and not Stackoverflow, I'm going to assume that you're asking a question about numeric analysis, and (to keep things simple) IEEE-754 floating point in particular. In that case, the answer to your question partly depends on what you mean by "easier", and partly on the details of the system.
No modern CPUs that I'm aware of have an instruction built in which does exactly what you'd expect either for either the $e^x$ operation (which henceforth we will call exp
, its usual name in C) or $2^x$ (exp2
). They are both implemented using library functions.
As is the case with all numeric methods for transcendental operations, there are a few special cases to consider:
exp(NaN) = NaN
exp(+Inf) = +Inf
exp(-Inf) = 0
However, there is another thing that makes the problem slightly less complicated: the useful domain is quite small. For binary32, exp(x)
underflows if $x < -104$ or so, and overflows if $x > 88.7$ or so. Unusually for transcendental operations, we can also ignore the subnormal case, since exp(x)
is indistinguishable from 1.0
if x
is subnormal. All of the above is also true for exp2
, except that the domain is slightly different.
Your intuition is right in that most implementations compute $e^x = 2^{x/\ln 2}$. However, the cost of that multiplication by $\frac{1}{\ln 2}$ is trivial compared to the rest of computing exp2
. A typical method uses a precomputed table with $K$ elements:
$$\hbox{exp2}(x) = 2^n \times T[j] \times P(y)$$
where $n$ is the integer part of $x$, the table $T$ contains values of $2^{j/K}$ for all $j$ in the range $[0,K)$, and $P$ is some polynomial approximation to $2^x$ (quartic is sufficient for binary32) in the range $[0,\frac{1}{K})$. The $2^n$ part is cheap, since it's just manipulating the exponent. $T$ is a lookup table. So $P$ is likely to be the expensive part of the operation.
I should point out for completeness that Intel x86 FPUs include an instruction called f2xm1
, which computes $2^x-1$ for $x$ in the range $[-1,1]$. However, on a modern CPU, this is a fairly expensive and non-pipelined instruction, and you are highly discouraged from using it. As the Intel Optimization Reference Manual Section 3.8.5 rightly notes:
Although x87 supports transcendental instructions, software library
implementation of transcendental function can be faster in many cases.
Edit: It's been pointed out in the comments that I should explain some of the new terminology used in IEEE 754-2008. Some of the language has changed since 1985 and 1987, and most people are far more familiar with the old jargon.
The terms "binary32" and "binary64" are the new names for 32-bit and 64-bit binary floating-point numbers, which the old standard called "single" and "double" respectively.
The term "subnormal number" replaces the previous term "denormal number" or "denormalized number".