Adjustments

This commit is contained in:
Alexey Milovidov 2021-02-14 23:57:25 +03:00
parent 55c17ac93f
commit d529db5498
2 changed files with 7 additions and 4 deletions

View File

@ -6,11 +6,11 @@
#include <Common/NaNUtils.h> #include <Common/NaNUtils.h>
#include <DataTypes/NumberTraits.h> #include <DataTypes/NumberTraits.h>
#if !defined(ARCADIA_BUILD) #if !defined(ARCADIA_BUILD)
# include <Common/config.h> # include <Common/config.h>
#endif #endif
namespace DB namespace DB
{ {
@ -90,20 +90,22 @@ struct DivideIntegralImpl
} }
else else
{ {
/// Comparisons are not strict to avoid rounding issues when operand is implicitly casted to float.
if constexpr (std::is_floating_point_v<A>) if constexpr (std::is_floating_point_v<A>)
if (isNaN(a) || a > std::numeric_limits<CastA>::max() || a < std::numeric_limits<CastA>::lowest()) if (isNaN(a) || a >= std::numeric_limits<CastA>::max() || a <= std::numeric_limits<CastA>::lowest())
throw Exception("Cannot perform integer division on infinite or too large floating point numbers", throw Exception("Cannot perform integer division on infinite or too large floating point numbers",
ErrorCodes::ILLEGAL_DIVISION); ErrorCodes::ILLEGAL_DIVISION);
if constexpr (std::is_floating_point_v<B>) if constexpr (std::is_floating_point_v<B>)
if (isNaN(b) || b > std::numeric_limits<CastB>::max() || b < std::numeric_limits<CastB>::lowest()) if (isNaN(b) || b >= std::numeric_limits<CastB>::max() || b <= std::numeric_limits<CastB>::lowest())
throw Exception("Cannot perform integer division on infinite or too large floating point numbers", throw Exception("Cannot perform integer division on infinite or too large floating point numbers",
ErrorCodes::ILLEGAL_DIVISION); ErrorCodes::ILLEGAL_DIVISION);
auto res = checkedDivision(CastA(a), CastB(b)); auto res = checkedDivision(CastA(a), CastB(b));
if constexpr (std::is_floating_point_v<decltype(res)>) if constexpr (std::is_floating_point_v<decltype(res)>)
if (isNaN(res) || res > std::numeric_limits<Result>::max() || res < std::numeric_limits<Result>::lowest()) if (isNaN(res) || res >= std::numeric_limits<Result>::max() || res <= std::numeric_limits<Result>::lowest())
throw Exception("Cannot perform integer division, because it will produce infinite or too large number", throw Exception("Cannot perform integer division, because it will produce infinite or too large number",
ErrorCodes::ILLEGAL_DIVISION); ErrorCodes::ILLEGAL_DIVISION);

View File

@ -1 +1,2 @@
SELECT intDiv(9223372036854775807, 0.9998999834060669); -- { serverError 153 } SELECT intDiv(9223372036854775807, 0.9998999834060669); -- { serverError 153 }
SELECT intDiv(9223372036854775807, 1.); -- { serverError 153 }