Lesson

MySQL EXP() Function

10 min reading
Free Course

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 raise e to.

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 DOUBLE overflows past roughly 709.78. Calling EXP(710) throws ERROR 1690 (22003): DOUBLE value is out of range in 'exp(710)'. Cap extreme scores with LEAST(x, 700) before calling EXP().
  • Confusing EXP() with POW(): EXP(x) always uses base e, whereas POW(b, x) lets you choose any base b.
  • NULL inputs: Passing NULL to EXP(NULL) returns NULL.

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).

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
MySQL Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum