The LOG2 SQL Function in MySQL and MariaDB - Logarithm to the base 2
LOG2
Syntax:
LOG2(Number)
Return value:
FLOAT
Function type:
Numeric function
Function Description
The LOG2() function returns the logarithm based on 2 of "Number".
If the value of Number is less than or equal to 0, NULL is returned.
If "Number" is NULL, NULL is returned.
SQL Examples for the LOG2 function
1 2 3 4 5
selectlog2(2.4) as result;selectlog2(2) as result;selectlog2(-2) as result;
result
double(23)
1.2630344058337937
result
double(23)
1
result
double(23)
NULL
The examples were created with the MyWAY SQL manager: Download
How to use the LOG2() function in MySQL and MariaDB databases
The LOG2() function in MySQL and MariaDB is used when there is a need to calculate base 2 logarithms, for example when working with logarithmic scales or analyzing data that follow a base 2 logarithmic relationship. The function uses floating-point arithmetic, so the precision of the result depends on the underlying data type.