With MySQL, we can do complex calculations very easily with the help of inbuilt mathematical functions. LN(X) function is used to get the natural logarithm of the number X.
Now let’s start with it.
LN(X) is a mathematical function. It returns the natural logarithm of a number X ; that means, the base-e logarithm of X. Where X is the value passed as an argument.
It will return NULL, if X is passed as NULL.
It will returns NULL and a warning “Invalid argument for logarithm” is reported, If X is less than or equal to 0.0E0, the function
Name, Required /Optional, Description
X , Required, Double, It represents a valid number for fetching log value.
Return, Description
NULL, if the argument is NULL.
Double, It returns the natural logarithm of a number X .
Now, Let’s see some of the basic examples of it and see what it returns.
mysql> SELECT LN(5); +--------------------+ | LN(5) | +--------------------+ | 1.6094379124341003 | +--------------------+ 1 row in set (0.01 sec) mysql> SELECT LN(8.56); +--------------------+ | LN(8.56) | +--------------------+ | 2.1471001901536506 | +--------------------+ 1 row in set (0.00 sec) mysql> SELECT LN(1); +-------+ | LN(1) | +-------+ | 0 | +-------+ 1 row in set (0.00 sec)
Now, Let’s see an example with a negative value and see what it returns.
mysql> SELECT LN(-5); +--------+ | LN(-5) | +--------+ | NULL | +--------+ 1 row in set, 1 warning (0.03 sec) mysql> SHOW WARNINGS; +---------+------+--------------------------------+ | Level | Code | Message | +---------+------+--------------------------------+ | Warning | 3020 | Invalid argument for logarithm | +---------+------+--------------------------------+ 1 row in set (0.00 sec) mysql> SELECT LN(0); +-------+ | LN(0) | +-------+ | NULL | +-------+ 1 row in set, 1 warning (0.00 sec) mysql> SHOW WARNINGS; +---------+------+--------------------------------+ | Level | Code | Message | +---------+------+--------------------------------+ | Warning | 3020 | Invalid argument for logarithm | +---------+------+--------------------------------+ 1 row in set (0.00 sec)
We have got the NULL as output and a warning has been issued. Warning data can also be seen with the help of ‘SHOW WARNINGS;’ command. You can see the above code for the same.
We are using the LN() function with expressions. See the below example.
mysql> SELECT LN(1+1); +--------------------+ | LN(1+1) | +--------------------+ | 0.6931471805599453 | +--------------------+ 1 row in set (0.00 sec) mysql> SELECT LN(4.67+11.89); +--------------------+ | LN(4.67+11.89) | +--------------------+ | 2.8069901489571136 | +--------------------+ 1 row in set (0.00 sec) mysql> SELECT LN(3*2); +-------------------+ | LN(3*2) | +-------------------+ | 1.791759469228055 | +-------------------+ 1 row in set (0.01 sec) mysql> SELECT LN(3.8*2.2); +--------------------+ | LN(3.8*2.2) | +--------------------+ | 2.1234584270966104 | +--------------------+ 1 row in set (0.00 sec)
If the argument is NULL, it will return NULL. See the below example :
mysql> SELECT LN(NULL); +----------+ | LN(NULL) | +----------+ | NULL | +----------+ 1 row in set (0.00 sec)
App usage is growing steadily without showing any signs of slowing down. Hence, it is no surprise that mobile applications…
As the world has grown more digital, businesses have adapted themselves. An effectual adaptation includes online advertising. Offline advertising styles…
Step into a world where apps dance to the user's tune. Picture Instagram, a photo-sharing sensation that swept the globe.…
COVID-19 has led to a digitalization of lifestyle. As patients are taking their mental and physical health more seriously, healthcare…
Introduction WordPress, an immensely popular content management system (CMS), powers over 40% of the internet. What makes WordPress even more…
For moving companies trying to capture their market share amidst stiff competition, a tip or two about what they can…