From e960efd5e63e4de51151724db92e6c2548aa88d9 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 19 Aug 2016 06:17:53 +0300 Subject: [PATCH] Changed semantic of intDiv, intDivOrZero functions for floating point arguments [#METR-19446]. --- dbms/include/DB/Functions/FunctionsArithmetic.h | 4 ++-- dbms/include/DB/Functions/NumberTraits.h | 2 +- .../queries/0_stateless/00369_int_div_of_float.reference | 6 ++++++ dbms/tests/queries/0_stateless/00369_int_div_of_float.sql | 6 ++++++ 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 dbms/tests/queries/0_stateless/00369_int_div_of_float.reference create mode 100644 dbms/tests/queries/0_stateless/00369_int_div_of_float.sql diff --git a/dbms/include/DB/Functions/FunctionsArithmetic.h b/dbms/include/DB/Functions/FunctionsArithmetic.h index ef5ab5a055e..7f8bfae3bcd 100644 --- a/dbms/include/DB/Functions/FunctionsArithmetic.h +++ b/dbms/include/DB/Functions/FunctionsArithmetic.h @@ -174,7 +174,7 @@ struct DivideIntegralImpl static inline Result apply(A a, B b) { throwIfDivisionLeadsToFPE(a, b); - return static_cast(a) / b; + return a / b; } }; @@ -186,7 +186,7 @@ struct DivideIntegralOrZeroImpl template static inline Result apply(A a, B b) { - return unlikely(divisionLeadsToFPE(a, b)) ? 0 : static_cast(a) / b; + return unlikely(divisionLeadsToFPE(a, b)) ? 0 : a / b; } }; diff --git a/dbms/include/DB/Functions/NumberTraits.h b/dbms/include/DB/Functions/NumberTraits.h index 65490ada02a..d1f2c8c037e 100644 --- a/dbms/include/DB/Functions/NumberTraits.h +++ b/dbms/include/DB/Functions/NumberTraits.h @@ -134,7 +134,7 @@ template struct ResultOfIntegerDivision { typedef typename Construct< typename boost::mpl::or_::Sign, typename Traits::Sign>::type, - typename boost::mpl::or_::Floatness, typename Traits::Floatness>::type, + Integer, typename Traits::Bits>::Type Type; }; diff --git a/dbms/tests/queries/0_stateless/00369_int_div_of_float.reference b/dbms/tests/queries/0_stateless/00369_int_div_of_float.reference new file mode 100644 index 00000000000..ec6b3a01e43 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00369_int_div_of_float.reference @@ -0,0 +1,6 @@ +2 +2 +2 +2 +3 +3 diff --git a/dbms/tests/queries/0_stateless/00369_int_div_of_float.sql b/dbms/tests/queries/0_stateless/00369_int_div_of_float.sql new file mode 100644 index 00000000000..4d5d477ceeb --- /dev/null +++ b/dbms/tests/queries/0_stateless/00369_int_div_of_float.sql @@ -0,0 +1,6 @@ +SELECT intDiv(10, 4); +SELECT intDiv(10., 4); +SELECT intDiv(10, 4.); +SELECT intDiv(10., 4.); +SELECT intDiv(1, 0.3); +SELECT intDiv(1.0, 0.3);