MariaDB LOG2() Function
In MariaDB, LOG2()
is a built-in function that returns the base-2 logarithm of a given value.
MariaDB LOG2()
syntax
Here is the syntax of the MariaDB LOG2()
function:
LOG2(number)
LOG2(number)
is equivalent to LOG(2, number)
.
Parameters
number
-
Required. A number used to calculate the logarithm. The value must be greater than
0
.
If you provide the wrong number of parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'LOG2'
.
Return value
The MariaDB LOG2()
function returns the base 2 logarithm of the specified number.
If the parameter number
is less than or equal to 0
, the LOG2()
function will return NULL
.
If the parameter number
is NULL
, the LOG2()
function will return NULL
.
MariaDB LOG2()
Examples
This statement shows the basic usage of the MariaDB LOG2()
function:
SELECT
LOG2(1),
LOG2(2),
LOG2(16),
LOG2(-1),
LOG2(NULL)\G
Output:
LOG2(1): 0
LOG2(2): 1
LOG2(16): 4
LOG2(-1): NULL
LOG2(NULL): NULL
Conclusion
In MariaDB, LOG2()
is a built-in function that returns the base-2 logarithm of a given value.