1#include <IO/readFloatText.h>
2
3namespace DB
4{
5
6namespace ErrorCodes
7{
8 extern const int CANNOT_PARSE_INPUT_ASSERTION_FAILED;
9}
10
11/** Must successfully parse inf, INF and Infinity.
12 * All other variants in different cases are also parsed for simplicity.
13 */
14bool parseInfinity(ReadBuffer & buf)
15{
16 if (!checkStringCaseInsensitive("inf", buf))
17 return false;
18
19 /// Just inf.
20 if (buf.eof() || !isWordCharASCII(*buf.position()))
21 return true;
22
23 /// If word characters after inf, it should be infinity.
24 return checkStringCaseInsensitive("inity", buf);
25}
26
27
28/** Must successfully parse nan, NAN and NaN.
29 * All other variants in different cases are also parsed for simplicity.
30 */
31bool parseNaN(ReadBuffer & buf)
32{
33 return checkStringCaseInsensitive("nan", buf);
34}
35
36
37void assertInfinity(ReadBuffer & buf)
38{
39 if (!parseInfinity(buf))
40 throw Exception("Cannot parse infinity.", ErrorCodes::CANNOT_PARSE_INPUT_ASSERTION_FAILED);
41}
42
43void assertNaN(ReadBuffer & buf)
44{
45 if (!parseNaN(buf))
46 throw Exception("Cannot parse NaN.", ErrorCodes::CANNOT_PARSE_INPUT_ASSERTION_FAILED);
47}
48
49
50template void readFloatTextPrecise<Float32>(Float32 &, ReadBuffer &);
51template void readFloatTextPrecise<Float64>(Float64 &, ReadBuffer &);
52template bool tryReadFloatTextPrecise<Float32>(Float32 &, ReadBuffer &);
53template bool tryReadFloatTextPrecise<Float64>(Float64 &, ReadBuffer &);
54
55template void readFloatTextFast<Float32>(Float32 &, ReadBuffer &);
56template void readFloatTextFast<Float64>(Float64 &, ReadBuffer &);
57template bool tryReadFloatTextFast<Float32>(Float32 &, ReadBuffer &);
58template bool tryReadFloatTextFast<Float64>(Float64 &, ReadBuffer &);
59
60template void readFloatTextSimple<Float32>(Float32 &, ReadBuffer &);
61template void readFloatTextSimple<Float64>(Float64 &, ReadBuffer &);
62template bool tryReadFloatTextSimple<Float32>(Float32 &, ReadBuffer &);
63template bool tryReadFloatTextSimple<Float64>(Float64 &, ReadBuffer &);
64
65template void readFloatText<Float32>(Float32 &, ReadBuffer &);
66template void readFloatText<Float64>(Float64 &, ReadBuffer &);
67template bool tryReadFloatText<Float32>(Float32 &, ReadBuffer &);
68template bool tryReadFloatText<Float64>(Float64 &, ReadBuffer &);
69
70}
71