mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-17256 Decimal field multiplication bug.
We should clear trailing zeroes in frac part. Otherwise that tail is growing quickly and forces unnecessary truncating of arguments.
This commit is contained in:
@ -2077,26 +2077,21 @@ int decimal_mul(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
|
||||
}
|
||||
}
|
||||
|
||||
/* Now we have to check for -0.000 case */
|
||||
if (to->sign)
|
||||
/* Remove trailing zero words in frac part */
|
||||
frac0= ROUND_UP(to->frac);
|
||||
|
||||
if (frac0 > 0 && to->buf[intg0 + frac0 - 1] == 0)
|
||||
{
|
||||
dec1 *buf= to->buf;
|
||||
dec1 *end= to->buf + intg0 + frac0;
|
||||
DBUG_ASSERT(buf != end);
|
||||
for (;;)
|
||||
do
|
||||
{
|
||||
if (*buf)
|
||||
break;
|
||||
if (++buf == end)
|
||||
{
|
||||
/* We got decimal zero */
|
||||
decimal_make_zero(to);
|
||||
break;
|
||||
}
|
||||
}
|
||||
frac0--;
|
||||
} while (frac0 > 0 && to->buf[intg0 + frac0 - 1] == 0);
|
||||
to->frac= DIG_PER_DEC1 * frac0;
|
||||
}
|
||||
|
||||
/* Remove heading zero words in intg part */
|
||||
buf1= to->buf;
|
||||
d_to_move= intg0 + ROUND_UP(to->frac);
|
||||
d_to_move= intg0 + frac0;
|
||||
while (!*buf1 && (to->intg > DIG_PER_DEC1))
|
||||
{
|
||||
buf1++;
|
||||
@ -2109,6 +2104,14 @@ int decimal_mul(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
|
||||
for (; d_to_move--; cur_d++, buf1++)
|
||||
*cur_d= *buf1;
|
||||
}
|
||||
|
||||
/* Now we have to check for -0.000 case */
|
||||
if (to->sign && to->frac == 0 && to->buf[0] == 0)
|
||||
{
|
||||
DBUG_ASSERT(to->intg <= DIG_PER_DEC1);
|
||||
/* We got decimal zero */
|
||||
decimal_make_zero(to);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user