MySQL EXP() Function
MySQL EXP() Function: Calculating Base-e Exponentials
The EXP() function returns Euler's number e (approximately 2.7182818) raised to the power of a given number. It is the exact mathematical inverse of the natural logarithm function LN().
Data analysts use EXP() for continuous compound interest, exponential decay models in churn scoring, and logistic probability curves. It always outputs a DOUBLE floating-point number.
Syntax
EXP(x)
x: Numeric exponent to raiseeto.
Practical Example
Suppose demo_products models continuous demand decay (decay_rate per week) for seasonal inventory over weeks_elapsed. Using EXP(-decay_rate * weeks_elapsed) estimates remaining demand factor.
SELECT
product_id,
product_name,
decay_rate,
weeks_elapsed,
ROUND(EXP(-decay_rate * weeks_elapsed), 4) AS demand_factor
FROM demo_products
WHERE decay_rate IS NOT NULL;
| product_id | product_name | decay_rate | weeks_elapsed | demand_factor |
|---|---|---|---|---|
| 31 | Winter Parka | 0.15 | 4 | 0.5488 |
| 32 | Wool Scarf | 0.10 | 0 | 1.0000 |
| 33 | Snow Boots | 0.25 | 8 | 0.1353 |
At week 0, EXP(0) equals 1.0000. After 8 weeks with a 0.25 decay rate, demand drops to 0.1353 of its starting baseline.
Common Mistakes & NULL Behavior
- DOUBLE overflow on large exponents: IEEE 754
DOUBLEoverflows past roughly709.78. CallingEXP(710)throwsERROR 1690 (22003): DOUBLE value is out of range in 'exp(710)'. Cap extreme scores withLEAST(x, 700)before callingEXP(). - Confusing EXP() with POW():
EXP(x)always uses basee, whereasPOW(b, x)lets you choose any baseb. - NULL inputs: Passing
NULLtoEXP(NULL)returnsNULL.
Frequently Asked Questions
What does EXP(1) return in MySQL?
EXP(1) returns Euler's number e: 2.718281828459045.
Can I pass negative numbers to EXP()?
Yes. Negative exponents return positive fractions between 0 and 1. For example, EXP(-1) returns 0.36787944117144233. Very large negative values underflow smoothly to 0.
How do EXP() and LN() undo each other?
For any positive number x, EXP(LN(x)) restores x, and for any valid real number y, LN(EXP(y)) restores y (within floating-point rounding).
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.