Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
5c933d63
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,发现更多精彩内容 >>
提交
5c933d63
编写于
1月 14, 2018
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed error #1665
上级
460cba0e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
70 addition
and
9 deletion
+70
-9
dbms/src/IO/readFloatText.h
dbms/src/IO/readFloatText.h
+70
-9
未找到文件。
dbms/src/IO/readFloatText.h
浏览文件 @
5c933d63
...
...
@@ -9,13 +9,22 @@
/** Methods for reading floating point numbers from text with decimal representation.
* There are "precise", "fast" and "simple" implementations.
*
* Neither of methods support hexadecimal numbers (0xABC), binary exponent (1p100), leading plus sign.
*
* Precise method always returns a number that is the closest machine representable number to the input.
* Fast method is faster and usually return the same value, but result may differ from precise method.
* Simple method is even faster for cases of parsing short (few digit) integers, but less precise and slower in other cases.
*
* Fast method is faster (up to 3 times) and usually return the same value,
* but in rare cases result may differ by lest significant bit from precise method.
* Also fast method may parse some garbage as some other unspecified garbage.
*
* Simple method is little faster for cases of parsing short (few digit) integers, but less precise and slower in other cases.
* It's not recommended to use simple method and it is left only for reference.
*
* For performance test, look at 'read_float_perf' test.
*
* For precision test:
* For precision test.
* Parse all existing Float32 numbers:
CREATE TABLE test.floats ENGINE = Log AS SELECT reinterpretAsFloat32(reinterpretAsString(toUInt32(number))) AS x FROM numbers(0x100000000);
...
...
@@ -31,6 +40,51 @@ FROM test.floats
WHERE NOT isNaN(x)
GROUP BY diff
ORDER BY diff ASC
LIMIT 100
* Here are the results:
*
Precise:
┌─diff─┬────count()─┐
│ 0 │ 4278190082 │
└──────┴────────────┘
(100% roundtrip property)
Fast:
┌─diff─┬────count()─┐
│ 0 │ 3685260580 │
│ 1 │ 592929502 │
└──────┴────────────┘
(The difference is 1 in least significant bit in 13.8% of numbers.)
Simple:
┌─diff─┬────count()─┐
│ 0 │ 2169879994 │
│ 1 │ 1807178292 │
│ 2 │ 269505944 │
│ 3 │ 28826966 │
│ 4 │ 2566488 │
│ 5 │ 212878 │
│ 6 │ 18276 │
│ 7 │ 1214 │
│ 8 │ 30 │
└──────┴────────────┘
* Parse random Float64 numbers:
WITH
rand64() AS bin_x,
reinterpretAsFloat64(reinterpretAsString(bin_x)) AS x,
toFloat64(toString(x)) AS y,
reinterpretAsUInt64(reinterpretAsString(y)) AS bin_y,
abs(bin_x - bin_y) AS diff
SELECT
diff,
count()
FROM numbers(100000000)
WHERE NOT isNaN(x)
GROUP BY diff
ORDER BY diff ASC
LIMIT 100
*/
...
...
@@ -212,7 +266,7 @@ ReturnType readFloatTextPreciseImpl(T & x, ReadBuffer & buf)
template
<
size_t
N
,
typename
T
>
void
readUIntTextUpToN
Char
s
(
T
&
x
,
ReadBuffer
&
buf
)
void
readUIntTextUpToN
SignificantDigit
s
(
T
&
x
,
ReadBuffer
&
buf
)
{
/// In optimistic case we can skip bound checking for first loop.
if
(
buf
.
position
()
+
N
<=
buf
.
buffer
().
end
())
...
...
@@ -283,7 +337,7 @@ ReturnType readFloatTextFastImpl(T & x, ReadBuffer & in)
auto
count_after_sign
=
in
.
count
();
constexpr
int
significant_digits
=
std
::
numeric_limits
<
UInt64
>::
digits10
;
readUIntTextUpToN
Char
s
<
significant_digits
>
(
before_point
,
in
);
readUIntTextUpToN
SignificantDigit
s
<
significant_digits
>
(
before_point
,
in
);
int
read_digits
=
in
.
count
()
-
count_after_sign
;
...
...
@@ -308,15 +362,22 @@ ReturnType readFloatTextFastImpl(T & x, ReadBuffer & in)
if
(
checkChar
(
'.'
,
in
))
{
auto
after_point_count
=
in
.
count
();
readUIntTextUpToNChars
<
significant_digits
>
(
after_point
,
in
);
int
read_digits
=
in
.
count
()
-
after_point_count
;
after_point_exponent
=
read_digits
>
significant_digits
?
-
significant_digits
:
-
read_digits
;
while
(
!
in
.
eof
()
&&
*
in
.
position
()
==
'0'
)
++
in
.
position
();
auto
after_leading_zeros_count
=
in
.
count
();
auto
after_point_num_leading_zeros
=
after_leading_zeros_count
-
after_point_count
;
readUIntTextUpToNSignificantDigits
<
significant_digits
>
(
after_point
,
in
);
int
read_digits
=
in
.
count
()
-
after_leading_zeros_count
;
after_point_exponent
=
(
read_digits
>
significant_digits
?
-
significant_digits
:
-
read_digits
)
-
after_point_num_leading_zeros
;
}
if
(
checkChar
(
'e'
,
in
)
||
checkChar
(
'E'
,
in
))
{
bool
exponent_negative
=
checkChar
(
'-'
,
in
);
readUIntTextUpToN
Char
s
<
4
>
(
exponent
,
in
);
readUIntTextUpToN
SignificantDigit
s
<
4
>
(
exponent
,
in
);
if
(
exponent_negative
)
exponent
=
-
exponent
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录