summaryrefslogtreecommitdiff
path: root/strings/decimal.c
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2018-11-06 08:41:48 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2018-11-06 08:41:48 +0200
commit32062cc61cd00e4cd3b7939c8a09f9c3ac34ec76 (patch)
tree098d64b7c988bab8cca25b0f716d92f6f7e72ed9 /strings/decimal.c
parentaf9649c722810eb1754953eb406a84ec876ce693 (diff)
parentbae21bfb5de17328c33c3da8d191c6d3af14ae02 (diff)
downloadmariadb-git-32062cc61cd00e4cd3b7939c8a09f9c3ac34ec76.tar.gz
Merge 10.1 into 10.2
Diffstat (limited to 'strings/decimal.c')
-rw-r--r--strings/decimal.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/strings/decimal.c b/strings/decimal.c
index 029a85b3202..e085edd156a 100644
--- a/strings/decimal.c
+++ b/strings/decimal.c
@@ -2084,26 +2084,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++;
@@ -2116,6 +2111,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;
}