blob: 3c54ab0d8abfb2acaf925202e9f43981b72363ea [file] [view]
---
{
"title": "LOG2",
"language": "en",
"description": "Returns the logarithm of x to base 2."
}
---
## Description
Returns the logarithm of `x` to base `2`.
## Syntax
```sql
LOG2(<x>)
```
## Parameters
| Parameter | Description |
|-----------|------------|
| `<x>` | Antilogarithm should be greater than 0 |
## Return value
Returns a floating-point number. Special cases:
- If x IS NULL, return `NULL`
- If x IS NaN, return NaN
## Example
```sql
select log2(1);
```
```text
+-------------------------+
| log2(cast(1 as DOUBLE)) |
+-------------------------+
| 0.0 |
+-------------------------+
```
```sql
select log2(2);
```
```text
+-------------------------+
| log2(cast(2 as DOUBLE)) |
+-------------------------+
| 1.0 |
+-------------------------+
```
```sql
select log2(10);
```
```text
+--------------------------+
| log2(cast(10 as DOUBLE)) |
+--------------------------+
| 3.3219280948873626 |
+--------------------------+
```
```sql
select log2(NULL);
```
```text
+------------+
| log2(NULL) |
+------------+
| NULL |
+------------+
```
```sql
select log2(cast('Nan' as double));
```
```text
+-----------------------------+
| log2(cast('Nan' as double)) |
+-----------------------------+
| NaN |
+-----------------------------+
```