From 3ddd2771d65ff10940894f89045c641b396466a4 Mon Sep 17 00:00:00 2001 From: "hf@deer.(none)" <> Date: Thu, 7 Jul 2005 20:28:47 +0500 Subject: [PATCH] Fix for bug #11708 (real function returns wrongly rounded decimal) --- mysql-test/r/type_newdecimal.result | 3 +++ mysql-test/t/type_newdecimal.test | 5 +++++ sql/item_func.cc | 11 +++++++++++ sql/item_func.h | 1 + 4 files changed, 20 insertions(+) diff --git a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result index 9ff4aea0567..f4e75402009 100644 --- a/mysql-test/r/type_newdecimal.result +++ b/mysql-test/r/type_newdecimal.result @@ -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 diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test index 41129870d6f..92f0bc9024b 100644 --- a/mysql-test/t/type_newdecimal.test +++ b/mysql-test/t/type_newdecimal.test @@ -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; diff --git a/sql/item_func.cc b/sql/item_func.cc index 16296266234..db78c811eb9 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -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; diff --git a/sql/item_func.h b/sql/item_func.h index f6bc35e1617..3ca37b1961f 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -187,6 +187,7 @@ public: Item_real_func(Item *a,Item *b) :Item_func(a,b) {} Item_real_func(List &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; }