1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

ull2dec: exact calculation of the precision

This commit is contained in:
Sergei Golubchik
2016-06-25 23:02:32 +02:00
parent 4dcbb775ae
commit da372fb9dc
3 changed files with 8 additions and 9 deletions

View File

@ -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;
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

View File

@ -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

View File

@ -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--)
{ {