From da372fb9dc33e6b3ca65b7454aaec2b5c9bd9d73 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 25 Jun 2016 23:02:32 +0200 Subject: [PATCH] ull2dec: exact calculation of the precision --- mysql-test/r/bigint.result | 4 ++-- mysql-test/r/dyncol.result | 10 +++++----- strings/decimal.c | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/bigint.result b/mysql-test/r/bigint.result index 9810c2ea72b..fd613525aa1 100644 --- a/mysql-test/r/bigint.result +++ b/mysql-test/r/bigint.result @@ -385,7 +385,7 @@ def -((9223372036854775808)) 8 20 20 N 32897 0 63 -9223372036854775808 select -(-(9223372036854775808)); Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def -(-(9223372036854775808)) 246 21 19 N 32897 0 63 +def -(-(9223372036854775808)) 246 20 19 N 32897 0 63 -(-(9223372036854775808)) 9223372036854775808 select --9223372036854775808, ---9223372036854775808, ----9223372036854775808; @@ -402,7 +402,7 @@ drop table t1; create table t1 select -9223372036854775809 bi; describe t1; Field Type Null Key Default Extra -bi decimal(20,0) NO NULL +bi decimal(19,0) NO NULL drop table t1; # # Bug #45360: wrong results diff --git a/mysql-test/r/dyncol.result b/mysql-test/r/dyncol.result index 88b2afb2d70..1c26ca16153 100644 --- a/mysql-test/r/dyncol.result +++ b/mysql-test/r/dyncol.result @@ -91,19 +91,19 @@ hex(COLUMN_CREATE(1, NULL AS decimal)) 000000 select hex(COLUMN_CREATE(1, 1212 AS decimal)); hex(COLUMN_CREATE(1, 1212 AS decimal)) -0001000100040900800004BC +000100010004040084BC select hex(COLUMN_CREATE(1, 7 AS decimal)); hex(COLUMN_CREATE(1, 7 AS decimal)) -000100010004090080000007 +000100010004010087 select hex(COLUMN_CREATE(1, 8 AS decimal)); hex(COLUMN_CREATE(1, 8 AS decimal)) -000100010004090080000008 +000100010004010088 select hex(COLUMN_CREATE(1, 127 AS decimal)); hex(COLUMN_CREATE(1, 127 AS decimal)) -00010001000409008000007F +0001000100040300807F select hex(COLUMN_CREATE(1, 128 AS decimal)); hex(COLUMN_CREATE(1, 128 AS decimal)) -000100010004090080000080 +00010001000403008080 select hex(COLUMN_CREATE(1, 12.12 AS decimal)); hex(COLUMN_CREATE(1, 12.12 AS decimal)) 00010001000402028C0C diff --git a/strings/decimal.c b/strings/decimal.c index 5f451d668e3..c958a366957 100644 --- a/strings/decimal.c +++ b/strings/decimal.c @@ -1005,8 +1005,7 @@ static int ull2dec(ulonglong from, decimal_t *to) error=E_DEC_OVERFLOW; } to->frac=0; - /* intg can't be bigger than number of digits in a ulonglong (20) */ - to->intg= MY_MIN(intg1*DIG_PER_DEC1, 20); + for(to->intg= (intg1-1)*DIG_PER_DEC1; from; to->intg++, from/=10) {} for (buf=to->buf+intg1; intg1; intg1--) {