Skip to content

Commit

Permalink
[opt](functions) update some numeric functions docs (#1811)
Browse files Browse the repository at this point in the history
## Versions 

- [x] dev
- [x] 3.0
- [x] 2.1
- [ ] 2.0

## Languages

- [x] Chinese
- [x] English

## Docs Checklist

- [ ] Checked by AI
- [ ] Test Cases Built
  • Loading branch information
chaoyangqi authored Jan 21, 2025
1 parent bec1850 commit 2596fb2
Show file tree
Hide file tree
Showing 36 changed files with 1,173 additions and 966 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,44 @@ specific language governing permissions and limitations
under the License.
-->

## sqrt
## Description

### description
#### Syntax
Returns the square root of a value, where the input value must be greater than or equal to 0. Special cases:

`DOUBLE sqrt(DOUBLE x)`
Returns the square root of `x`.`x` is required to be greater than or equal to `0`.
- If the parameter is less than 0, returns NULL.

:::tip
Another alias for this function is `dsqrt`.
:::
## Aliases

### example
- DSQRT

## Syntax

```sql
SQRT(<a>)
```
mysql> select sqrt(9);
+-----------+
| sqrt(9.0) |
+-----------+
| 3 |
+-----------+
mysql> select sqrt(2);
+--------------------+
| sqrt(2.0) |
+--------------------+
| 1.4142135623730951 |
+--------------------+
mysql> select sqrt(100.0);
+-------------+
| sqrt(100.0) |
+-------------+
| 10 |
+-------------+

## Parameters

| Parameter | Description |
| -- | -- |
| `<a>` | The value whose square root is to be calculated |

## Return Value

The square root of parameter a. Special cases:

- If the parameter is less than 0, returns NULL

## Example

```sql
select sqrt(9),sqrt(2),sqrt(-1)
```

### keywords
SQRT, DSQRT
```text
+-------------------------+-------------------------+--------------------------+
| sqrt(cast(9 as DOUBLE)) | sqrt(cast(2 as DOUBLE)) | sqrt(cast(-1 as DOUBLE)) |
+-------------------------+-------------------------+--------------------------+
| 3 | 1.4142135623730951 | NULL |
+-------------------------+-------------------------+--------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,36 @@ specific language governing permissions and limitations
under the License.
-->

## tan
## Description

### description
#### Syntax
Returns the tangent of x, where x is the value in radians.

`DOUBLE tan(DOUBLE x)`
Returns the tangent of `x`, where `x` is in radians.

### example
## Syntax

```sql
TAN(<x>)
```
mysql> select tan(0);
+----------+
| tan(0.0) |
+----------+
| 0 |
+----------+
mysql> select tan(1);
+--------------------+
| tan(1.0) |
+--------------------+
| 1.5574077246549023 |
+--------------------+

## Parameters

| Parameter | Description |
| -- | -- |
| `<x>` | The value for which the tangent is to be calculated |

## Return Value

Returns the tangent of x.

## Example

```sql
select tan(0),tan(1),tan(-1);
```

### keywords
TAN
```text
+------------------------+------------------------+-------------------------+
| tan(cast(0 as DOUBLE)) | tan(cast(1 as DOUBLE)) | tan(cast(-1 as DOUBLE)) |
+------------------------+------------------------+-------------------------+
| 0 | 1.5574077246549023 | -1.5574077246549023 |
+------------------------+------------------------+-------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,36 @@ specific language governing permissions and limitations
under the License.
-->

## tanh
## Description

### description
#### Syntax
Returns the hyperbolic tangent of x.

`DOUBLE tanh(DOUBLE x)`
Returns the hyperbolic tangent of `x`, tanh(x) = sinh(x) / cosh(x).

### example
## Syntax

```sql
TANH(<x>)
```
mysql> select tanh(0);
+---------+
| tanh(0) |
+---------+
| 0 |
+---------+
mysql> select tanh(1);
+---------------------+
| tanh(1) |
+---------------------+
| 0.76159415595576485 |
+---------------------+

## Parameters

| Parameter | Description |
| -- | -- |
| `<x>` | The value for which the hyperbolic tangent is to be calculated |

## Return Value

The hyperbolic tangent of parameter x.

## Example

```sql
select tanh(0),tanh(1);
```

### keywords
TANH
```text
+-------------------------+-------------------------+
| tanh(cast(0 as DOUBLE)) | tanh(cast(1 as DOUBLE)) |
+-------------------------+-------------------------+
| 0 | 0.7615941559557649 |
+-------------------------+-------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,58 @@ specific language governing permissions and limitations
under the License.
-->

## truncate
## Description

### description
#### Syntax
`DOUBLE truncate(DOUBLE x, INT d)`
Perform numerical truncation on x to the number of decimal places d

Numerically truncate `x` according to the number of decimal places `d`.
## Syntax

The rules are as follows:
```sql
TRUNCATE(<x>, <d>)
```

## Parameters

| Parameter | Description |
| -- | -- |
| `<x>` | The value that needs to be numerically truncated |
| `<d>` | The number of decimal places to retain |

## Return Value

Perform numerical truncation on x to the number of decimal places d. Truncation rules:

If d is a literal:

- When d > 0: Keep d decimal places of x.
- When d = 0: Remove the decimal part of x and retain only the integer part.
- When d < 0: Remove the decimal part of x and replace the integer part with the number of digits specified by d, using the digit 0.

If `d` is literal:
When `d > 0`: keep `d` decimal places of `x`
When `d = 0`: remove the fractional part of `x` and keep only the integer part
When `d < 0`: Remove the fractional part of `x`, and replace the integer part with the number `0` according to the number of digits specified by `d`
If d is a column, and the first argument is of type Decimal, then the resulting Decimal will have the same number of decimal places as the input Decimal

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

### example
d is a litera

```sql
select truncate(124.3867, 2),truncate(124.3867, 0),truncate(124.3867, -2);
```
mysql> select truncate(124.3867, 2);
+-----------------------+
| truncate(124.3867, 2) |
+-----------------------+
| 124.38 |
+-----------------------+
mysql> select truncate(124.3867, 0);
+-----------------------+
| truncate(124.3867, 0) |
+-----------------------+
| 124 |
+-----------------------+
mysql> select truncate(-124.3867, -2);
+-------------------------+
| truncate(-124.3867, -2) |
+-------------------------+
| -100 |
+-------------------------+
mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5");
--------------

```text
+-----------------------+-----------------------+------------------------+
| truncate(124.3867, 2) | truncate(124.3867, 0) | truncate(124.3867, -2) |
+-----------------------+-----------------------+------------------------+
| 124.38 | 124 | 100 |
+-----------------------+-----------------------+------------------------+
```

d is a column

```sql
select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.123456" as Decimal(9,6)), number) from numbers("number"="5");
```

```text
+---------------------------------------+--------+----------------------------------------------------------------------+
| cast('123.123456' as DECIMALV3(9, 6)) | number | truncate(cast('123.123456' as DECIMALV3(9, 6)), cast(number as INT)) |
+---------------------------------------+--------+----------------------------------------------------------------------+
Expand All @@ -72,6 +84,3 @@ mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast ("123.12
| 123.123456 | 4 | 123.123400 |
+---------------------------------------+--------+----------------------------------------------------------------------+
```

### keywords
TRUNCATE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
{
"title": "uuid_numeric",
"title": "UUID_NUMERIC",
"language": "en"
}
---
Expand All @@ -24,28 +24,30 @@ specific language governing permissions and limitations
under the License.
-->

## uuid_numeric
### description
#### Syntax
## Description

`LARGEINT uuid_numeric()`
Return a LARGEINT type uuid

Return a uuid in type `LARGEINT`.
## Syntax

Note that `LARGEINT` has type Int128, so we could get a negative number from `uuid_numeric()`.
```sql
UUID_NUMERIC()
```

## Return Value

### example
Return a LARGEINT type uuid. Note that LARGEINT is an Int128, so uuid_numeric() may produce negative values

## Example

```sql
select uuid_numeric()
```

mysql> select uuid_numeric();
```text
+----------------------------------------+
| uuid_numeric() |
+----------------------------------------+
| 82218484683747862468445277894131281464 |
+----------------------------------------+
```

### keywords

UUID UUID-NUMERIC
Loading

0 comments on commit 2596fb2

Please sign in to comment.