diff options
author | Sergei Golubchik <serg@mariadb.org> | 2018-10-31 10:32:48 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2018-10-31 10:53:22 +0100 |
commit | a6e000049401eeebccae82e1fc040cbe9b04c66a (patch) | |
tree | 6b19c452e735d07d1f69940e38bdb10761ec0c96 /strings | |
parent | f4eec7fab076503177be7f51c438d1cd80cd723c (diff) | |
parent | 09e97299ba893b7578cac8160b3b687b0594aeee (diff) | |
download | mariadb-git-a6e000049401eeebccae82e1fc040cbe9b04c66a.tar.gz |
Merge branch '10.0' into 10.1
Diffstat (limited to 'strings')
-rw-r--r-- | strings/decimal.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/strings/decimal.c b/strings/decimal.c index c6898cd099f..bbfb4e9dc8b 100644 --- a/strings/decimal.c +++ b/strings/decimal.c @@ -2078,26 +2078,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++; @@ -2110,6 +2105,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; } |