Skip to content

Commit 4a95686

Browse files
authored
[doc](function)add docs for math even, signbit, gcd ,lcm (#2558)
## Versions - [x] dev - [ ] 3.0 - [ ] 2.1 - [ ] 2.0 ## Languages - [x] Chinese - [x] English ## Docs Checklist - [ ] Checked by AI - [ ] Test Cases Built
1 parent 8e06891 commit 4a95686

File tree

9 files changed

+700
-0
lines changed

9 files changed

+700
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
{
3+
"title": "EVEN",
4+
"language": "en"
5+
}
6+
---
7+
8+
<!--
9+
Licensed to the Apache Software Foundation (ASF) under one
10+
or more contributor license agreements. See the NOTICE file
11+
distributed with this work for additional information
12+
regarding copyright ownership. The ASF licenses this file
13+
to you under the Apache License, Version 2.0 (the
14+
"License"); you may not use this file except in compliance
15+
with the License. You may obtain a copy of the License at
16+
17+
http://www.apache.org/licenses/LICENSE-2.0
18+
19+
Unless required by applicable law or agreed to in writing,
20+
software distributed under the License is distributed on an
21+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22+
KIND, either express or implied. See the License for the
23+
specific language governing permissions and limitations
24+
under the License.
25+
-->
26+
27+
## Description
28+
29+
Round to next even number by rounding away from zero.
30+
31+
## Syntax
32+
33+
```sql
34+
EVEN(<a>)
35+
```
36+
37+
38+
## Parameters
39+
40+
| Parameter | Description |
41+
| -- | -- |
42+
| `<a>` | A numeric expression to round to the next even integer |
43+
44+
## Return Value
45+
46+
Returns the smallest even integer that is greater than or equal to x when x > 0, or less than or equal to x when x < 0.
47+
48+
## Examples
49+
50+
```sql
51+
select even(2.9);
52+
```
53+
54+
```text
55+
+----------+
56+
| even(2.9) |
57+
+----------+
58+
| 4 |
59+
+----------+
60+
```
61+
62+
```sql
63+
select even(-2.9);
64+
```
65+
66+
```text
67+
+-----------+
68+
| even(-2.9) |
69+
+-----------+
70+
| -4 |
71+
+-----------+
72+
```
73+
74+
```sql
75+
select even(4);
76+
```
77+
78+
```text
79+
+--------+
80+
| even(4) |
81+
+--------+
82+
| 4 |
83+
+--------+
84+
```
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
{
3+
"title": "GCD",
4+
"language": "en"
5+
}
6+
---
7+
8+
<!--
9+
Licensed to the Apache Software Foundation (ASF) under one
10+
or more contributor license agreements. See the NOTICE file
11+
distributed with this work for additional information
12+
regarding copyright ownership. The ASF licenses this file
13+
to you under the Apache License, Version 2.0 (the
14+
"License"); you may not use this file except in compliance
15+
with the License. You may obtain a copy of the License at
16+
17+
http://www.apache.org/licenses/LICENSE-2.0
18+
19+
Unless required by applicable law or agreed to in writing,
20+
software distributed under the License is distributed on an
21+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22+
KIND, either express or implied. See the License for the
23+
specific language governing permissions and limitations
24+
under the License.
25+
-->
26+
27+
## Description
28+
29+
Calculates the greatest common divisor (GCD) of two integers.
30+
31+
## Syntax
32+
33+
```sql
34+
GCD(<a>, <b>)
35+
```
36+
37+
38+
## Parameters
39+
40+
| Parameter | Description |
41+
| -- | -- |
42+
| `<a>` | The first integer |
43+
| `<b>` | The second integer |
44+
45+
## Return Value
46+
47+
Returns the greatest common divisor of `<a>` and `<b>`.
48+
49+
## Examples
50+
51+
```sql
52+
select gcd(54, 24);
53+
```
54+
55+
```text
56+
+------------+
57+
| gcd(54,24) |
58+
+------------+
59+
| 6 |
60+
+------------+
61+
```
62+
63+
```sql
64+
select gcd(-17, 31);
65+
```
66+
67+
```text
68+
+-------------+
69+
| gcd(17,31) |
70+
+-------------+
71+
| 1 |
72+
+-------------+
73+
```
74+
75+
```sql
76+
select gcd(0, 10);
77+
```
78+
79+
```text
80+
+-----------+
81+
| gcd(0,10) |
82+
+-----------+
83+
| 10 |
84+
+-----------+
85+
```
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
{
3+
"title": "LCM",
4+
"language": "en"
5+
}
6+
---
7+
8+
<!--
9+
Licensed to the Apache Software Foundation (ASF) under one
10+
or more contributor license agreements. See the NOTICE file
11+
distributed with this work for additional information
12+
regarding copyright ownership. The ASF licenses this file
13+
to you under the Apache License, Version 2.0 (the
14+
"License"); you may not use this file except in compliance
15+
with the License. You may obtain a copy of the License at
16+
17+
http://www.apache.org/licenses/LICENSE-2.0
18+
19+
Unless required by applicable law or agreed to in writing,
20+
software distributed under the License is distributed on an
21+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22+
KIND, either express or implied. See the License for the
23+
specific language governing permissions and limitations
24+
under the License.
25+
-->
26+
27+
## Description
28+
29+
Calculates the least common multiple (LCM) of two integers.Note that the result may overflow.
30+
31+
## Syntax
32+
33+
```sql
34+
LCM(<a>, <b>)
35+
```
36+
37+
38+
## Parameters
39+
40+
| Parameter | Description |
41+
| -- | -- |
42+
| `<a>` | The first integer |
43+
| `<b>` | The second integer |
44+
45+
## Return Value
46+
47+
Returns the least common multiple of `<a>` and `<b>`.
48+
49+
## Examples
50+
51+
```sql
52+
select lcm(12, 18);
53+
```
54+
55+
```text
56+
+------------+
57+
| lcm(12,18) |
58+
+------------+
59+
| 36 |
60+
+------------+
61+
```
62+
63+
```sql
64+
select lcm(0, 10);
65+
```
66+
67+
```text
68+
+-----------+
69+
| lcm(0,10) |
70+
+-----------+
71+
| 0 |
72+
+-----------+
73+
```
74+
75+
```sql
76+
select lcm(-4, 6);
77+
```
78+
79+
```text
80+
+------------+
81+
| lcm(-4,6) |
82+
+------------+
83+
| 12|
84+
+------------+
85+
```
86+
87+
```sql
88+
select lcm(-170141183460469231731687303715884105728, 3);
89+
```
90+
91+
```text
92+
ERROR 1105 (HY000): errCode = 2, detailMessage = Can not convert to legacy literal: 510423550381407695195061911147652317184
93+
```
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
{
3+
"title": "SIGNBIT",
4+
"language": "en"
5+
}
6+
---
7+
8+
<!--
9+
Licensed to the Apache Software Foundation (ASF) under one
10+
or more contributor license agreements. See the NOTICE file
11+
distributed with this work for additional information
12+
regarding copyright ownership. The ASF licenses this file
13+
to you under the Apache License, Version 2.0 (the
14+
"License"); you may not use this file except in compliance
15+
with the License. You may obtain a copy of the License at
16+
17+
http://www.apache.org/licenses/LICENSE-2.0
18+
19+
Unless required by applicable law or agreed to in writing,
20+
software distributed under the License is distributed on an
21+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22+
KIND, either express or implied. See the License for the
23+
specific language governing permissions and limitations
24+
under the License.
25+
-->
26+
27+
## Description
28+
29+
Determine whether the sign bit of the given floating-point number is set.
30+
31+
## Syntax
32+
33+
```sql
34+
SIGNBIT(<a>)
35+
```
36+
37+
## Parameters
38+
39+
| Parameter | Description |
40+
| -- | -- |
41+
| `<a>` | Floating-point number to check the sign bit for |
42+
43+
## Return Value
44+
45+
Returns true if the sign bit of `<a>` is set (i.e., `<a>` is negative), otherwise returns false.
46+
47+
## Examples
48+
49+
```sql
50+
select signbit(-1.0);
51+
```
52+
53+
```text
54+
+-----------------------------+
55+
| signbit(cast(-1 as DOUBLE)) |
56+
+-----------------------------+
57+
| true |
58+
+-----------------------------+
59+
```
60+
61+
```sql
62+
select signbit(0.0);
63+
```
64+
65+
```text
66+
+----------------------------+
67+
| signbit(cast(0 as DOUBLE)) |
68+
+----------------------------+
69+
| false |
70+
+----------------------------+
71+
```
72+
73+
```sql
74+
select signbit(1.0);
75+
```
76+
77+
```text
78+
+----------------------------+
79+
| signbit(cast(1 as DOUBLE)) |
80+
+----------------------------+
81+
| false |
82+
+----------------------------+
83+
```

0 commit comments

Comments
 (0)