In MariaDB, EXP()
is a built-in function that returns the value of e (the base of natural logarithms) raised to the power of the argument.
The number e, also known as Euler’s number, is a mathematical constant approximately equal to 2.71828.
The inverse of EXP()
is the LN()
function or LOG()
function (when using the single argument syntax).
Syntax
The syntax goes like this:
EXP(X)
Where X
is the value for which to raise e to the power of.
Example
Here’s an example:
SELECT EXP(3);
Result:
+--------------------+ | EXP(3) | +--------------------+ | 20.085536923187668 | +--------------------+
We can get the value of e by passing 1:
SELECT EXP(1);
Result:
+-------------------+ | EXP(1) | +-------------------+ | 2.718281828459045 | +-------------------+
Fractions
The argument can contain a fractional part:
SELECT EXP(1.34178);
Result:
+------------------+ | EXP(1.34178) | +------------------+ | 3.82584745652595 | +------------------+
Negative Values
The argument can be negative:
SELECT EXP(-2);
Result:
+--------------------+ | EXP(-2) | +--------------------+ | 0.1353352832366127 | +--------------------+
Expressions
The argument can include expressions like this:
SELECT EXP(2 * 3);
Result:
+-------------------+ | EXP(2 * 3) | +-------------------+ | 403.4287934927351 | +-------------------+
Non-Numeric Arguments
Here’s an example of what happens when we provide a non-numeric argument:
SELECT EXP('Cat');
Result:
+------------+ | EXP('Cat') | +------------+ | 1 | +------------+ 1 row in set, 1 warning (0.000 sec)
Let’s see the warning:
SHOW WARNINGS;
Result:
+---------+------+-----------------------------------------+ | Level | Code | Message | +---------+------+-----------------------------------------+ | Warning | 1292 | Truncated incorrect DOUBLE value: 'Cat' | +---------+------+-----------------------------------------+
Null Arguments
EXP()
returns null
if the argument is null
:
SELECT EXP(null);
Result:
+-----------+ | EXP(null) | +-----------+ | NULL | +-----------+
Missing Arguments
Calling EXP()
with the wrong number of arguments, or without any arguments results in an error:
SELECT EXP();
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'EXP'
And:
SELECT EXP(10, 2);
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'EXP'