Commit ae76b743 authored by Tor Didriksen's avatar Tor Didriksen

Bug#12711164 - 61676: RESULT OF DIV WITH DECIMAL AND INTEGER DOES NOT MAKE SENSE

Truncate result of decimal division before converting to integer.


mysql-test/r/func_math.result:
  New test case.
mysql-test/t/func_math.test:
  New test case.
sql/item_func.cc:
  Item_func_int_div::val_int():
  Truncate result of decimal division before converting to integer.
parent fe57d0d5
......@@ -709,3 +709,22 @@ foo
select 999999999999999999999999999999999999999999999999999999999999999999999999999999999 % 0.0 as foo;
foo
NULL
#
# Bug#12711164 - 61676:
# RESULT OF DIV WITH DECIMAL AND INTEGER DOES NOT MAKE SENSE
#
select 5 div 2;
5 div 2
2
select 5.0 div 2.0;
5.0 div 2.0
2
select 5.0 div 2;
5.0 div 2
2
select 5 div 2.0;
5 div 2.0
2
select 5.9 div 2, 1.23456789e3 DIV 2, 1.23456789e9 DIV 2, 1.23456789e19 DIV 2;
5.9 div 2 1.23456789e3 DIV 2 1.23456789e9 DIV 2 1.23456789e19 DIV 2
2 617 617283945 6172839450000000000
......@@ -547,3 +547,14 @@ let $nine_81=
eval select $nine_81 % 0.1 as foo;
eval select $nine_81 % 0.0 as foo;
--echo #
--echo # Bug#12711164 - 61676:
--echo # RESULT OF DIV WITH DECIMAL AND INTEGER DOES NOT MAKE SENSE
--echo #
select 5 div 2;
select 5.0 div 2.0;
select 5.0 div 2;
select 5 div 2.0;
select 5.9 div 2, 1.23456789e3 DIV 2, 1.23456789e9 DIV 2, 1.23456789e19 DIV 2;
......@@ -1605,8 +1605,13 @@ longlong Item_func_int_div::val_int()
return 0;
}
my_decimal truncated;
const bool do_truncate= true;
if (my_decimal_round(E_DEC_FATAL_ERROR, &tmp, 0, do_truncate, &truncated))
DBUG_ASSERT(false);
longlong res;
if (my_decimal2int(E_DEC_FATAL_ERROR, &tmp, unsigned_flag, &res) &
if (my_decimal2int(E_DEC_FATAL_ERROR, &truncated, unsigned_flag, &res) &
E_DEC_OVERFLOW)
raise_integer_overflow();
return res;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment