Commit da372fb9 authored by Sergei Golubchik's avatar Sergei Golubchik

ull2dec: exact calculation of the precision

parent 4dcbb775
...@@ -385,7 +385,7 @@ def -((9223372036854775808)) 8 20 20 N 32897 0 63 ...@@ -385,7 +385,7 @@ def -((9223372036854775808)) 8 20 20 N 32897 0 63
-9223372036854775808 -9223372036854775808
select -(-(9223372036854775808)); select -(-(9223372036854775808));
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr 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))
9223372036854775808 9223372036854775808
select --9223372036854775808, ---9223372036854775808, ----9223372036854775808; select --9223372036854775808, ---9223372036854775808, ----9223372036854775808;
...@@ -402,7 +402,7 @@ drop table t1; ...@@ -402,7 +402,7 @@ drop table t1;
create table t1 select -9223372036854775809 bi; create table t1 select -9223372036854775809 bi;
describe t1; describe t1;
Field Type Null Key Default Extra Field Type Null Key Default Extra
bi decimal(20,0) NO NULL bi decimal(19,0) NO NULL
drop table t1; drop table t1;
# #
# Bug #45360: wrong results # Bug #45360: wrong results
......
...@@ -91,19 +91,19 @@ hex(COLUMN_CREATE(1, NULL AS decimal)) ...@@ -91,19 +91,19 @@ hex(COLUMN_CREATE(1, NULL AS decimal))
000000 000000
select hex(COLUMN_CREATE(1, 1212 AS decimal)); select hex(COLUMN_CREATE(1, 1212 AS decimal));
hex(COLUMN_CREATE(1, 1212 AS decimal)) hex(COLUMN_CREATE(1, 1212 AS decimal))
0001000100040900800004BC 000100010004040084BC
select hex(COLUMN_CREATE(1, 7 AS decimal)); select hex(COLUMN_CREATE(1, 7 AS decimal));
hex(COLUMN_CREATE(1, 7 AS decimal)) hex(COLUMN_CREATE(1, 7 AS decimal))
000100010004090080000007 000100010004010087
select hex(COLUMN_CREATE(1, 8 AS decimal)); select hex(COLUMN_CREATE(1, 8 AS decimal));
hex(COLUMN_CREATE(1, 8 AS decimal)) hex(COLUMN_CREATE(1, 8 AS decimal))
000100010004090080000008 000100010004010088
select hex(COLUMN_CREATE(1, 127 AS decimal)); select hex(COLUMN_CREATE(1, 127 AS decimal));
hex(COLUMN_CREATE(1, 127 AS decimal)) hex(COLUMN_CREATE(1, 127 AS decimal))
00010001000409008000007F 0001000100040300807F
select hex(COLUMN_CREATE(1, 128 AS decimal)); select hex(COLUMN_CREATE(1, 128 AS decimal));
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)); select hex(COLUMN_CREATE(1, 12.12 AS decimal));
hex(COLUMN_CREATE(1, 12.12 AS decimal)) hex(COLUMN_CREATE(1, 12.12 AS decimal))
00010001000402028C0C 00010001000402028C0C
......
...@@ -1005,8 +1005,7 @@ static int ull2dec(ulonglong from, decimal_t *to) ...@@ -1005,8 +1005,7 @@ static int ull2dec(ulonglong from, decimal_t *to)
error=E_DEC_OVERFLOW; error=E_DEC_OVERFLOW;
} }
to->frac=0; to->frac=0;
/* intg can't be bigger than number of digits in a ulonglong (20) */ for(to->intg= (intg1-1)*DIG_PER_DEC1; from; to->intg++, from/=10) {}
to->intg= MY_MIN(intg1*DIG_PER_DEC1, 20);
for (buf=to->buf+intg1; intg1; intg1--) for (buf=to->buf+intg1; intg1; intg1--)
{ {
......
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