Merge pull request #10272 from ClickHouse/plus-infinity

Allow to parse +inf
This commit is contained in:
alexey-milovidov 2020-04-15 16:41:47 +03:00 committed by GitHub
commit 7b2c871c57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 2 deletions

View File

@ -156,6 +156,9 @@ ReturnType readFloatTextPreciseImpl(T & x, ReadBuffer & buf)
{
switch (*buf.position())
{
case '+':
continue;
case '-':
{
negative = true;
@ -335,6 +338,7 @@ ReturnType readFloatTextFastImpl(T & x, ReadBuffer & in)
++in.position();
}
auto count_after_sign = in.count();
constexpr int significant_digits = std::numeric_limits<UInt64>::digits10;
@ -380,7 +384,7 @@ ReturnType readFloatTextFastImpl(T & x, ReadBuffer & in)
if (in.eof())
{
if constexpr (throw_exception)
throw Exception("Cannot read floating point value", ErrorCodes::CANNOT_PARSE_NUMBER);
throw Exception("Cannot read floating point value: nothing after exponent", ErrorCodes::CANNOT_PARSE_NUMBER);
else
return false;
}
@ -418,11 +422,30 @@ ReturnType readFloatTextFastImpl(T & x, ReadBuffer & in)
if (in.eof())
{
if constexpr (throw_exception)
throw Exception("Cannot read floating point value", ErrorCodes::CANNOT_PARSE_NUMBER);
throw Exception("Cannot read floating point value: no digits read", ErrorCodes::CANNOT_PARSE_NUMBER);
else
return false;
}
if (*in.position() == '+')
{
++in.position();
if (in.eof())
{
if constexpr (throw_exception)
throw Exception("Cannot read floating point value: nothing after plus sign", ErrorCodes::CANNOT_PARSE_NUMBER);
else
return false;
}
else if (negative)
{
if constexpr (throw_exception)
throw Exception("Cannot read floating point value: plus after minus sign", ErrorCodes::CANNOT_PARSE_NUMBER);
else
return false;
}
}
if (*in.position() == 'i' || *in.position() == 'I')
{
if (assertOrParseInfinity<throw_exception>(in))

View File

@ -0,0 +1,3 @@
inf
-inf
inf

View File

@ -0,0 +1,3 @@
SELECT DISTINCT toFloat64(arrayJoin(['+inf', '+Inf', '+INF', '+infinity', '+Infinity']));
SELECT DISTINCT toFloat64(arrayJoin(['-inf', '-Inf', '-INF', '-infinity', '-Infinity']));
SELECT DISTINCT toFloat64(arrayJoin(['inf', 'Inf', 'INF', 'infinity', 'Infinity']));