How to use EXP() to get Raise to the power of values in MySQL8?

With MySQL, we can do complex calculations very easily with the help of inbuilt mathematical functions. EXP(X) returns the value of e (the base of natural logarithms) raised to the power of X.

Now let’s start with it.


EXP(X) is a mathematical function. It returns the value of e (the base of natural logarithms) raised to the power of X. Where X is the value passed as an argument.

The constant e value is approximately 2.718281, is the base of natural logarithms.

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.

The opposite of this function is LOG() (using a single argument only) or LN().

It will return NULL, if X is passed as NULL.

It returns error, if any String argument is passed as an input.


MySQL EXP() : Syntax

EXP ( X );

MySQL EXP() : Parameter

Name, Required /Optional, Description
X , Required, Double , It represents a valid number.


MySQL EXP() : Output

Return, Description
NULL, if the argument is NULL.
Double, It returns the value of e (the base of natural logarithms) raised to the power of input number.


MySQL EXP()  Available from : MySQL 4.0


EXP() Example 1 : Basic Examples

Now, Let’s see some of the basic examples of it and see what it returns.

mysql> SELECT EXP(5);
+-------------------+
| EXP(5) |
+-------------------+
| 148.4131591025766 |
+-------------------+
1 row in set (0.00 sec)

EXP() Example 2 : Negative values

Now, Let’s see an example with a negative value and see what it returns.

mysql> SELECT EXP(-5);
+----------------------+
| EXP(-5) |
+----------------------+
| 0.006737946999085467 |
+----------------------+
1 row in set (0.07 sec)

EXP() Example 3 : Passing Zero (0) as an input

See the output, we have got 1 as result, when Zero (0) is passed as input.

mysql> SELECT EXP(0);
+--------+
| EXP(0) |
+--------+
| 1 |
+--------+
1 row in set (0.00 sec)

EXP() Example 4 : With Expressions

We are using the EXP() function with expressions. See the below example.

mmysql> SELECT EXP(1+1);
+------------------+
| EXP(1+1) |
+------------------+
| 7.38905609893065 |
+------------------+
1 row in set (0.04 sec)

mysql> SELECT EXP(3*2);
+-------------------+
| EXP(3*2) |
+-------------------+
| 403.4287934927351 |
+-------------------+
1 row in set (0.00 sec)

EXP() Example 5 : NULL arguments

If the argument is NULL, it will return NULL. See the below example :

mysql> SELECT EXP(NULL);
+-----------+
| EXP(NULL) |
+-----------+
| NULL |
+-----------+
1 row in set (0.52 sec)

EXP() Example 6 : RETURN the value of e

Passing 1 as a user input return the value of e (that is, e to the power of 1). See the below example :

mysql> SELECT EXP(1);
+-------------------+
| EXP(1) |
+-------------------+
| 2.718281828459045 |
+-------------------+
1 row in set (0.00 sec)

Related articles : PI(), MySQL Maths.

jyoti rani

Recent Posts

What Is a Progressive Web App? Why Would You Need One?

App usage is growing steadily without showing any signs of slowing down. Hence, it is no surprise that mobile applications…

1 year ago

7 Most Popular Paid Online Advertising Strategy

As the world has grown more digital, businesses have adapted themselves. An effectual adaptation includes online advertising. Offline advertising styles…

1 year ago

The Importance of User-Centered Design in Mobile App Development

Step into a world where apps dance to the user's tune. Picture Instagram, a photo-sharing sensation that swept the globe.…

1 year ago

Healthcare Mobile App Development: A Complete Guide for Founders

COVID-19 has led to a digitalization of lifestyle. As patients are taking their mental and physical health more seriously, healthcare…

1 year ago

Exploring Diverse WordPress Theme Niches: A Comprehensive Guide

Introduction WordPress, an immensely popular content management system (CMS), powers over 40% of the internet. What makes WordPress even more…

1 year ago

8 Awesome Blog Content Ideas for Movers to Skyrocket the SEO

For moving companies trying to capture their market share amidst stiff competition, a tip or two about what they can…

1 year ago