Commit d9846171 authored by unknown's avatar unknown
Browse files

Fix for bug #11708 (real function returns wrongly rounded decimal)


mysql-test/r/type_newdecimal.result:
  test result fixed
mysql-test/t/type_newdecimal.test:
  test case added
sql/item_func.cc:
  Item_real_func::val_decimal implemented
sql/item_func.h:
  Item_real_func::val_decimal declared
parent 995abb0e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -937,3 +937,6 @@ drop table t1;
select cast('1.00000001335143196001808973960578441619873046875E-10' as decimal(30,15));
cast('1.00000001335143196001808973960578441619873046875E-10' as decimal(30,15))
0.000000000100000
select ln(14000) c1, convert(ln(14000),decimal(2,3)) c2, cast(ln(14000) as decimal(2,3)) c3;
c1	c2	c3
9.5468126085974	9.547	9.547
+5 −0
Original line number Diff line number Diff line
@@ -978,3 +978,8 @@ drop table t1;
# Bug #10891 (converting to decimal crashes server)
#
select cast('1.00000001335143196001808973960578441619873046875E-10' as decimal(30,15));

#
# Bug #11708 (conversion to decimal fails in decimal part)
#
select ln(14000) c1, convert(ln(14000),decimal(2,3)) c2, cast(ln(14000) as decimal(2,3)) c3;
+11 −0
Original line number Diff line number Diff line
@@ -566,6 +566,17 @@ String *Item_real_func::val_str(String *str)
}


my_decimal *Item_real_func::val_decimal(my_decimal *decimal_value)
{
  DBUG_ASSERT(fixed);
  double nr= val_real();
  if (null_value)
    return 0; /* purecov: inspected */
  double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
  return decimal_value;
}


void Item_func::fix_num_length_and_dec()
{
  decimals= 0;
+1 −0
Original line number Diff line number Diff line
@@ -187,6 +187,7 @@ class Item_real_func :public Item_func
  Item_real_func(Item *a,Item *b) :Item_func(a,b) {}
  Item_real_func(List<Item> &list) :Item_func(list) {}
  String *val_str(String*str);
  my_decimal *val_decimal(my_decimal *decimal_value);
  longlong val_int()
    { DBUG_ASSERT(fixed == 1); return (longlong) val_real(); }
  enum Item_result result_type () const { return REAL_RESULT; }