Commit d3ee99ad authored by hf@deer.(none)'s avatar hf@deer.(none)

Fix for bug #8431 (FLOOR returns incorrect result)

parent af329d53
...@@ -733,6 +733,9 @@ abs(9999999999999999999999) ...@@ -733,6 +733,9 @@ abs(9999999999999999999999)
select abs(-9999999999999999999999); select abs(-9999999999999999999999);
abs(-9999999999999999999999) abs(-9999999999999999999999)
9999999999999999999999 9999999999999999999999
select ceiling(999999999999999999);
ceiling(999999999999999999)
999999999999999999
select ceiling(99999999999999999999); select ceiling(99999999999999999999);
ceiling(99999999999999999999) ceiling(99999999999999999999)
99999999999999999999 99999999999999999999
...@@ -741,13 +744,16 @@ ceiling(9.9999999999999999999) ...@@ -741,13 +744,16 @@ ceiling(9.9999999999999999999)
10 10
select ceiling(-9.9999999999999999999); select ceiling(-9.9999999999999999999);
ceiling(-9.9999999999999999999) ceiling(-9.9999999999999999999)
-10 -9
select floor(999999999999999999);
floor(999999999999999999)
999999999999999999
select floor(9999999999999999999999); select floor(9999999999999999999999);
floor(9999999999999999999999) floor(9999999999999999999999)
9999999999999999999999 9999999999999999999999
select floor(9.999999999999999999999); select floor(9.999999999999999999999);
floor(9.999999999999999999999) floor(9.999999999999999999999)
10 9
select floor(-9.999999999999999999999); select floor(-9.999999999999999999999);
floor(-9.999999999999999999999) floor(-9.999999999999999999999)
-10 -10
......
...@@ -601,6 +601,7 @@ select abs(9999999999999999999999); ...@@ -601,6 +601,7 @@ select abs(9999999999999999999999);
select abs(-9999999999999999999999); select abs(-9999999999999999999999);
#-- should return 9999999999999999999999 #-- should return 9999999999999999999999
# #
select ceiling(999999999999999999);
select ceiling(99999999999999999999); select ceiling(99999999999999999999);
#-- should return 99999999999999999999 #-- should return 99999999999999999999
# #
...@@ -610,6 +611,7 @@ select ceiling(9.9999999999999999999); ...@@ -610,6 +611,7 @@ select ceiling(9.9999999999999999999);
select ceiling(-9.9999999999999999999); select ceiling(-9.9999999999999999999);
#-- should return 9 #-- should return 9
# #
select floor(999999999999999999);
select floor(9999999999999999999999); select floor(9999999999999999999999);
#-- should return 9999999999999999999999 #-- should return 9999999999999999999999
# #
......
...@@ -1638,14 +1638,14 @@ longlong Item_func_ceiling::int_op() ...@@ -1638,14 +1638,14 @@ longlong Item_func_ceiling::int_op()
case DECIMAL_RESULT: case DECIMAL_RESULT:
{ {
my_decimal dec_buf, *dec; my_decimal dec_buf, *dec;
if ((dec= decimal_op(&dec_buf))) if ((dec= Item_func_ceiling::decimal_op(&dec_buf)))
my_decimal2int(E_DEC_FATAL_ERROR, dec, unsigned_flag, &result); my_decimal2int(E_DEC_FATAL_ERROR, dec, unsigned_flag, &result);
else else
result= 0; result= 0;
break; break;
} }
default: default:
result= (longlong)real_op(); result= (longlong)Item_func_ceiling::real_op();
}; };
return result; return result;
} }
...@@ -1676,13 +1676,25 @@ my_decimal *Item_func_ceiling::decimal_op(my_decimal *decimal_value) ...@@ -1676,13 +1676,25 @@ my_decimal *Item_func_ceiling::decimal_op(my_decimal *decimal_value)
longlong Item_func_floor::int_op() longlong Item_func_floor::int_op()
{ {
/* longlong result;
the volatile's for BUG #3051 to calm optimizer down (because of gcc's switch (args[0]->result_type()) {
bug) case INT_RESULT:
*/ result= args[0]->val_int();
volatile double value= args[0]->val_real();
null_value= args[0]->null_value; null_value= args[0]->null_value;
return (longlong) floor(value); break;
case DECIMAL_RESULT:
{
my_decimal dec_buf, *dec;
if ((dec= Item_func_floor::decimal_op(&dec_buf)))
my_decimal2int(E_DEC_FATAL_ERROR, dec, unsigned_flag, &result);
else
result= 0;
break;
}
default:
result= (longlong)Item_func_floor::real_op();
};
return result;
} }
......
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