A Quick Look at EXP() in SQLite

The exp() function in SQLite calculates the exponential of a given number, where the base is the mathematical constant e (approximately 2.71828). In other words, it returns e raised to the power of x for a given input x.

This function can be useful in scientific and statistical calculations involving exponential growth, decay, and other natural logarithmic-based transformations.

Syntax

exp(x)

Where x is the value for which you want to calculate e raised to the power of x.

Example

Suppose we have a table called Numbers:

CREATE TABLE Numbers (value REAL);
INSERT INTO Numbers (value) VALUES (1.0), (2.0), (0.0), (-1.0);

To calculate e raised to the power of x for each value in the value column:

SELECT value, exp(value) AS exponential_value FROM Numbers;

Output:

+-------+-------------------+
| value | exponential_value |
+-------+-------------------+
| 1.0 | 2.71828182845905 |
| 2.0 | 7.38905609893065 |
| 0.0 | 1.0 |
| -1.0 | 0.367879441171442 |
+-------+-------------------+

In this example:

  • exp(1.0) calculates e raised to the power of 1, which is approximately 2.71828182845905.
  • exp(2.0) calculates e raised to the power of 2, approximately 7.38905609893065.
  • exp(0.0) calculates e raised to the power of 0, which is always 1.
  • exp(-1.0) calculates e raised to the power of -1, approximately 0.367879441171442.

This function is especially useful in exponential functions or transformations.