Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc]New floor to fpow #1942

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,66 +22,105 @@ specific language governing permissions and limitations
under the License.
-->

## floor
## Description

### description
#### Syntax
It rounds a numerical value down to the nearest integer or an integer that is a specified multiple.

`T floor(T x[, d])`

If not specified `d`: returns the largest integer value less than or equal to `x`, which is **the most common usage**.
If not specified `d`: returns the largest integer value less than or equal to `x`, which is the most common usage.
Otherwise, returns the largest round number that is less than or equal to `x` and flowing the rules:

If `d` is specified as literal:
`d` = 0: just like without `d`
`d` > 0 or `d` < 0: the round number would be a multiple of `1/(10^d)`, or the nearest number of the appropriate data type if `1/(10^d)` isn't exact.
- `d` = 0: just like without `d`.
- `d` > 0 or `d` < 0: the round number would be a multiple of `1/(10^d)`, or the nearest number of the appropriate data type if `1/(10^d)` isn't exact.
- `d` = NULL: return NULL.

Else if `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal.

:::tip
Another alias for this function is `dfloor`.
:::
## Alias

- DFLOOR

### example
## Syntax

```sql
FLOOR(<x> [ , <d>])
```
mysql> select floor(1);
+------------+
| floor(1.0) |
+------------+
| 1 |
+------------+
mysql> select floor(2.4);

## Parameters

| Parameter | Description |
|-----------|------------|
| `<x>` | Independent Variable |
| `<d>` | Precision Parameter |

## Return value

Returns an integer or a floating-point number.

## Example

```sql
select floor(1);
```

```text
+-----------------------------------+
| floor(cast(1 as DECIMALV3(3, 0))) |
+-----------------------------------+
| 1 |
+-----------------------------------+
```

```sql
select floor(2.4);
```

```text
+------------+
| floor(2.4) |
+------------+
| 2 |
+------------+
mysql> select floor(-10.3);
```

```sql
select floor(-10.3);
```

```text
+--------------+
| floor(-10.3) |
+--------------+
| -11 |
+--------------+
mysql> select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1);
```

```sql
select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1);
```

```text
+------------------+---------------+------------------+-------------------+
| floor(123.45, 1) | floor(123.45) | floor(123.45, 0) | floor(123.45, -1) |
+------------------+---------------+------------------+-------------------+
| 123.4 | 123 | 123 | 120 |
+------------------+---------------+------------------+-------------------+
mysql> SELECT number
-> , floor(number * 2.5, number - 1) AS f_decimal_column
-> , floor(number * 2.5, 0) AS f_decimal_literal
-> , floor(cast(number * 2.5 AS DOUBLE), number - 1) AS f_double_column
-> , floor(cast(number * 2.5 AS DOUBLE), 0) AS f_double_literal
-> FROM test_enhanced_round
-> WHERE rid = 1;
```

```sql
SELECT number
, floor(number * 2.5, number - 1) AS f_decimal_column
, floor(number * 2.5, 0) AS f_decimal_literal
, floor(cast(number * 2.5 AS DOUBLE), number - 1) AS f_double_column
, floor(cast(number * 2.5 AS DOUBLE), 0) AS f_double_literal
FROM test_enhanced_round
WHERE rid = 1;
```

```text
+--------+------------------+-------------------+-----------------+------------------+
| number | f_decimal_column | f_decimal_literal | f_double_column | f_double_literal |
+--------+------------------+-------------------+-----------------+------------------+
| 1 | 2.0 | 2 | 2 | 2 |
+--------+------------------+-------------------+-----------------+------------------+
```

### keywords
FLOOR, DFLOOR
```

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,68 @@ specific language governing permissions and limitations
under the License.
-->

## log10
## Description

### description
#### Syntax

`DOUBLE log10(DOUBLE x)`
Returns the natural logarithm of `x` to base `10`.

:::tip
Another alias for this function is `dlog10`.
:::
## Alias

- DLOG10

## Syntax

```sql
LOG10(<x>)
```

## Parameters

| Parameter | Description |
|-----------|------------|
| `<x>` | Antilogarithm should be greater than 0 |

## Return value

Returns a floating-point number.

- If x IS NULL: return `NULL`

### example
## Example

```sql
select log10(1);
```
mysql> select log10(1);
+------------+
| log10(1.0) |
+------------+
| 0 |
+------------+
mysql> select log10(10);
+-------------+
| log10(10.0) |
+-------------+
| 1 |
+-------------+
mysql> select log10(16);
+--------------------+
| log10(16.0) |
+--------------------+
| 1.2041199826559248 |
+--------------------+

```text
+--------------------------+
| log10(cast(1 as DOUBLE)) |
+--------------------------+
| 0.0 |
+--------------------------+
```

```sql
select log10(10);
```

```text
+---------------------------+
| log10(cast(10 as DOUBLE)) |
+---------------------------+
| 1.0 |
+---------------------------+
```

### keywords
LOG10, DLOG10
```sql
select log10(16);
```

```text
+---------------------------+
| log10(cast(16 as DOUBLE)) |
+---------------------------+
| 1.2041199826559248 |
+---------------------------+
```


Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,62 @@ specific language governing permissions and limitations
under the License.
-->

## log2
## Description

### description
#### Syntax

`DOUBLE log2(DOUBLE x)`
Returns the natural logarithm of `x` to base `2`.

### example
## Syntax

```sql
LOG2(<x>)
```
mysql> select log2(1);
+-----------+
| log2(1.0) |
+-----------+
| 0 |
+-----------+
mysql> select log2(2);
+-----------+
| log2(2.0) |
+-----------+
| 1 |
+-----------+
mysql> select log2(10);
+--------------------+
| log2(10.0) |
+--------------------+
| 3.3219280948873622 |
+--------------------+

## Parameters

| Parameter | Description |
|-----------|------------|
| `<x>` | Antilogarithm should be greater than 0 |

## Return value

Returns a floating-point number.

- If x IS NULL: return `NULL`

## Example

```sql
select log2(1);
```

### keywords
LOG2
```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 |
+--------------------------+
```

This file was deleted.

This file was deleted.

Loading