The exp() function computes ex—Euler’s number e (about 2.718) raised to a power. It models continuous growth and decay, powers hyperbolic functions like cosh(), and pairs with log() as its inverse.
01
e^x
Natural exp.
02
math.h
Link with -lm.
03
exp(0)=1
Identity.
04
exp(1)=e
Base constant.
05
Inverse
log().
06
vs pow
Prefer exp.
Fundamentals
Definition and Usage
The natural exponential function is written ex in mathematics. In C, exp(x) computes this value, where e ≈ 2.718281828 is Euler’s number—the unique base where the slope of the curve ex at zero equals 1.
Positive x gives growth (values rise quickly). Negative x gives decay (values shrink toward zero). At x = 0, any number to the power 0 is 1, so exp(0) = 1.
💡
Beginner Tip
Need e2? Write exp(2.0), not pow(2.718, 2). The exp function is designed for this and is more accurate than approximating e yourself.
log undoes exp. When you need to solve ex = y for x, use x = log(y).
Applications
🚀 Common Use Cases
Finance — continuous compound interest and discounting.
Physics — radioactive decay, capacitor charging, population growth.
Probability — softmax, Poisson distribution, entropy calculations.
Machine learning — sigmoid and log-softmax use exp internally.
Hyperbolic functions — cosh(x) and sinh(x) are built from exp.
🧠 How exp() Works
1
Receive exponent x
Any real number—positive, negative, or zero.
Input
2
Compute e^x
Library uses range reduction and polynomial approximation.
Compute
3
Return double
Always positive (except underflow to 0). Never negative.
Output
=
🔢
Exponential value
Use log(y) to reverse when y > 0.
Important
📝 Notes
Computes ex, not 10x (use pow(10, x) or exp(x * log(10)) for base 10).
exp(0) = 1; exp(1) = e.
Result is always positive; exp(x) > 0 for all finite x.
Large positive x → overflow (INFINITY); large negative x → underflow (0).
Prefer exp(x) over pow(M_E, x) for accuracy and speed.
Inverse: log(exp(x)) == x for finite x.
Performance
⚡ Optimization
exp() is heavily optimized in modern math libraries. If you call it repeatedly with the same exponent in a loop, cache the result in a variable. For softmax-style code summing many exponentials, use the log-sum-exp trick to avoid overflow—subtract the maximum value before calling exp.
Wrap Up
Conclusion
exp() raises Euler’s number to a power, modeling growth and decay across science and finance. Remember exp(0) = 1, use log() as its inverse, and prefer exp over manual pow for ex.
Continue with fabs() for absolute values, or explore log() for natural logarithms.
exp(x) returns e raised to the power x, where e is Euler's number (about 2.71828). For example, exp(0) is 1.0, exp(1) is about 2.718, and exp(2) is about 7.389.
Include <math.h> and link with -lm on many systems: gcc program.c -o program -lm. The function is declared as double exp(double x).
e (Euler's number) is the mathematical constant approximately 2.718281828. It is the base of the natural logarithm. exp(1) equals e exactly (within floating-point precision).
exp(x) computes e^x. log(x) computes the natural logarithm ln(x)—the inverse operation. log(exp(x)) equals x, and exp(log(x)) equals x for positive x.
Prefer exp(x) for e^x. It is typically faster and more accurate than pow(M_E, x). Use pow only when the base is not e.
Very large positive x may overflow to +INFINITY. Very large negative x approaches 0 (underflow). Check with isinf() or isfinite() if inputs can be extreme.
Did you know?
The constant e appears in the formula for continuously compounded interest: A = P · ert. As compounding intervals shrink toward zero, discrete compound interest approaches this exponential form—which is exactly what exp() computes.