Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
167618f7
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
167618f7
编写于
11月 23, 2017
作者:
A
alexey-milovidov
提交者:
GitHub
11月 23, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1538 from samael500/stable
Add missing test for GCD/LCM functions.
上级
d21a2a05
a06ca9cb
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
100 addition
and
8 deletion
+100
-8
dbms/src/Functions/FunctionsArithmetic.h
dbms/src/Functions/FunctionsArithmetic.h
+8
-8
dbms/tests/queries/0_stateless/00515_gcd_lcm.reference
dbms/tests/queries/0_stateless/00515_gcd_lcm.reference
+34
-0
dbms/tests/queries/0_stateless/00515_gcd_lcm.sql
dbms/tests/queries/0_stateless/00515_gcd_lcm.sql
+38
-0
docs/en/functions/arithmetic_functions.rst
docs/en/functions/arithmetic_functions.rst
+10
-0
docs/ru/functions/arithmetic_functions.md
docs/ru/functions/arithmetic_functions.md
+10
-0
未找到文件。
dbms/src/Functions/FunctionsArithmetic.h
浏览文件 @
167618f7
...
...
@@ -439,11 +439,11 @@ struct GCDImpl
template
<
typename
Result
=
ResultType
>
static
inline
Result
apply
(
A
a
,
B
b
)
{
throwIfDivisionLeadsToFPE
(
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
),
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
));
throwIfDivisionLeadsToFPE
(
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
),
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
));
throwIfDivisionLeadsToFPE
(
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
),
typename
NumberTraits
::
ToInteger
<
B
>::
Type
(
b
));
throwIfDivisionLeadsToFPE
(
typename
NumberTraits
::
ToInteger
<
B
>::
Type
(
b
),
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
));
return
boost
::
math
::
gcd
(
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
),
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
));
typename
NumberTraits
::
ToInteger
<
Result
>::
Type
(
a
),
typename
NumberTraits
::
ToInteger
<
Result
>::
Type
(
b
));
}
};
...
...
@@ -455,11 +455,11 @@ struct LCMImpl
template
<
typename
Result
=
ResultType
>
static
inline
Result
apply
(
A
a
,
B
b
)
{
throwIfDivisionLeadsToFPE
(
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
),
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
));
throwIfDivisionLeadsToFPE
(
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
),
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
));
throwIfDivisionLeadsToFPE
(
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
),
typename
NumberTraits
::
ToInteger
<
B
>::
Type
(
b
));
throwIfDivisionLeadsToFPE
(
typename
NumberTraits
::
ToInteger
<
B
>::
Type
(
b
),
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
));
return
boost
::
math
::
lcm
(
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
),
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
));
typename
NumberTraits
::
ToInteger
<
Result
>::
Type
(
a
),
typename
NumberTraits
::
ToInteger
<
Result
>::
Type
(
b
));
}
};
...
...
dbms/tests/queries/0_stateless/00515_gcd_lcm.reference
0 → 100644
浏览文件 @
167618f7
256
11
64
1
2
1
1
1
2147483647
1
5120
121
256
1
4
735
64770
4611686011984936962
4611686011984936962
2147483648
256
11
64
1
2
1
1
5120
121
256
1
4
735
64770
dbms/tests/queries/0_stateless/00515_gcd_lcm.sql
0 → 100644
浏览文件 @
167618f7
-- test gcd
select
gcd
(
1280
,
1024
);
select
gcd
(
11
,
121
);
select
gcd
(
-
256
,
64
);
select
gcd
(
1
,
1
);
select
gcd
(
4
,
2
);
select
gcd
(
15
,
49
);
select
gcd
(
255
,
254
);
select
gcd
(
2147483647
,
2147483646
);
select
gcd
(
4611686011984936962
,
2147483647
);
select
gcd
(
-
2147483648
,
1
);
-- test lcm
select
lcm
(
1280
,
1024
);
select
lcm
(
11
,
121
);
select
lcm
(
-
256
,
64
);
select
lcm
(
1
,
1
);
select
lcm
(
4
,
2
);
select
lcm
(
15
,
49
);
select
lcm
(
255
,
254
);
select
lcm
(
2147483647
,
2147483646
);
select
lcm
(
4611686011984936962
,
2147483647
);
select
lcm
(
-
2147483648
,
1
);
-- test gcd float will cast to int
select
gcd
(
1280
.
1
,
1024
.
1
);
select
gcd
(
11
.
1
,
121
.
1
);
select
gcd
(
-
256
.
1
,
64
.
1
);
select
gcd
(
1
.
1
,
1
.
1
);
select
gcd
(
4
.
1
,
2
.
1
);
select
gcd
(
15
.
1
,
49
.
1
);
select
gcd
(
255
.
1
,
254
.
1
);
-- test lcm float cast to int
select
lcm
(
1280
.
1
,
1024
.
1
);
select
lcm
(
11
.
1
,
121
.
1
);
select
lcm
(
-
256
.
1
,
64
.
1
);
select
lcm
(
1
.
1
,
1
.
1
);
select
lcm
(
4
.
1
,
2
.
1
);
select
lcm
(
15
.
1
,
49
.
1
);
select
lcm
(
255
.
1
,
254
.
1
);
docs/en/functions/arithmetic_functions.rst
浏览文件 @
167618f7
...
...
@@ -64,3 +64,13 @@ abs(a)
------
Calculates the absolute value of the number 'a'. That is, if a< 0, it returns -a.
For unsigned types, it doesn't do anything. For signed integer types, it returns an unsigned number.
gcd(a, b)
---------
Calculates the greatest common divisor of the numbers.
When dividing by zero or when dividing a minimal negative number by minus one, an exception is thrown.
lcm(a, b)
---------
Calculates the least common multiple of the numbers.
When dividing by zero or when dividing a minimal negative number by minus one, an exception is thrown.
docs/ru/functions/arithmetic_functions.md
浏览文件 @
167618f7
...
...
@@ -73,3 +73,13 @@ abs(a)
Вычисляет абсолютное значение для числа a. То есть, если a
<
0, то возвращает -a.
Для беззнаковых типов ничего не делает. Для чисел типа целых со знаком, возвращает число беззнакового типа.
gcd(a, b)
---------
Вычисляет наибольший общий делитель чисел.
При делении на ноль или при делении минимального отрицательного числа на минус единицу, кидается исключение.
lcm(a, b)
---------
Вычисляет наименьшее общее кратное чисел.
При делении на ноль или при делении минимального отрицательного числа на минус единицу, кидается исключение.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录