MySQL EXP() Function – Return e Raised to the Power of x

In MySQL, the EXP() function returns e raised to the power of a specified value.

You provide the specified value as an argument when calling the function.

The number e is a mathematical constant that is the base of the natural logarithm: the unique number whose natural logarithm is equal to one. It is approximately equal to 2.71828.

Syntax

The syntax goes like this:

EXP(X)

Where X is the value for which e will be raised to the power of.

Example 1 – Basic Usage

Here’s a basic example to demonstrate how this function works.

SELECT EXP(2);

Result:

+------------------+
| EXP(2)           |
+------------------+
| 7.38905609893065 |
+------------------+

Example 2 – Negative Value

Here’s an example using a negative value.

SELECT EXP(-2);

Result:

+--------------------+
| EXP(-2)            |
+--------------------+
| 0.1353352832366127 |
+--------------------+

Example 3 – Zero

Here’s an example of passing in zero as the argument.

SELECT EXP(0);

Result:

+--------+
| EXP(0) |
+--------+
|      1 |
+--------+

Example 4 – Expressions

You can also pass in expressions like this:

SELECT EXP(1+1);

Result:

+------------------+
| EXP(1+1)         |
+------------------+
| 7.38905609893065 |
+------------------+

Example 5 – Return the Value of e

Passing in 1 returns the value of e (that is, e to the power of 1).

SELECT EXP(1);

Result:

+-------------------+
| EXP(1)            |
+-------------------+
| 2.718281828459045 |
+-------------------+