diff --git a/dbms/src/Functions/intDiv.cpp b/dbms/src/Functions/intDiv.cpp index 74727766841..a8e2d725625 100644 --- a/dbms/src/Functions/intDiv.cpp +++ b/dbms/src/Functions/intDiv.cpp @@ -33,7 +33,7 @@ struct DivideIntegralByConstantImpl { size_t size = a.size(); for (size_t i = 0; i < size; ++i) - c[i] = -c[i]; + c[i] = -a[i]; return; } diff --git a/dbms/tests/queries/0_stateless/00977_int_div.reference b/dbms/tests/queries/0_stateless/00977_int_div.reference index d3d73cb3798..39e135d8eed 100644 --- a/dbms/tests/queries/0_stateless/00977_int_div.reference +++ b/dbms/tests/queries/0_stateless/00977_int_div.reference @@ -21,3 +21,63 @@ 0 0 0 +-1 +-2 +-3 +-4 +-5 +-6 +-7 +-8 +-9 +-10 +-1 +-2 +-3 +-4 +-5 +-6 +-7 +-8 +-9 +-10 +-1 +-2 +-3 +-4 +-5 +-6 +-7 +-8 +-9 +-10 +-1 +-2 +-3 +-4 +-5 +-6 +-7 +-8 +-9 +-10 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 diff --git a/dbms/tests/queries/0_stateless/00977_int_div.sql b/dbms/tests/queries/0_stateless/00977_int_div.sql index 3270ab34224..08085020ca5 100644 --- a/dbms/tests/queries/0_stateless/00977_int_div.sql +++ b/dbms/tests/queries/0_stateless/00977_int_div.sql @@ -1,14 +1,14 @@ -SELECT - sum(ASD) AS asd, - intDiv(toInt64(asd), abs(toInt64(asd))) AS int_div_with_abs, +SELECT + sum(ASD) AS asd, + intDiv(toInt64(asd), abs(toInt64(asd))) AS int_div_with_abs, intDiv(toInt64(asd), toInt64(asd)) AS int_div_without_abs -FROM +FROM ( SELECT ASD - FROM + FROM ( SELECT [-1000, -1000] AS asds - ) + ) ARRAY JOIN asds AS ASD ); @@ -17,3 +17,9 @@ SELECT intDivOrZero( CAST(-1000, 'Int64') , CAST(1000, 'Int64') ); SELECT intDiv(-1, number) FROM numbers(1, 10); SELECT intDivOrZero(-1, number) FROM numbers(1, 10); +SELECT intDiv(toInt32(number), -1) FROM numbers(1, 10); +SELECT intDivOrZero(toInt32(number), -1) FROM numbers(1, 10); +SELECT intDiv(toInt64(number), -1) FROM numbers(1, 10); +SELECT intDivOrZero(toInt64(number), -1) FROM numbers(1, 10); +SELECT intDiv(number, -number) FROM numbers(1, 10); +SELECT intDivOrZero(number, -number) FROM numbers(1, 10);