diff options
author | Sergei Golubchik <sergii@pisem.net> | 2014-03-20 09:50:45 +0100 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2014-03-20 09:50:45 +0100 |
commit | 9ff0c9f730a79d4dab4303163d45c919f612cc37 (patch) | |
tree | da8b8f122ae3133407c424059a67b5a22cfe063d /strings/decimal.c | |
parent | 47f438675b81848700822426b28281cd3158e83b (diff) | |
download | mariadb-git-9ff0c9f730a79d4dab4303163d45c919f612cc37.tar.gz |
MDEV-5858 MySQL Bug#12744991 - DECIMAL_ROUND(X,D) GIVES WRONG RESULTS WHEN D == N*(-9)
don't use mysql-5.6 change.
correct fix: zero-out rounded tail after the number was shifted because
of the carry digit (otherwise the carry digit will be zeroed out too).
Diffstat (limited to 'strings/decimal.c')
-rw-r--r-- | strings/decimal.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/strings/decimal.c b/strings/decimal.c index 2156e095315..1b6ffbb110b 100644 --- a/strings/decimal.c +++ b/strings/decimal.c @@ -1594,24 +1594,6 @@ decimal_round(const decimal_t *from, decimal_t *to, int scale, x+=10; *buf1=powers10[pos]*(x-y); } - /* - In case we're rounding e.g. 1.5e9 to 2.0e9, the decimal_digit_t's inside - the buffer are as follows. - - Before <1, 5e8> - After <2, 5e8> - - Hence we need to set the 2nd field to 0. - The same holds if we round 1.5e-9 to 2e-9. - */ - if (frac0 < frac1) - { - dec1 *buf= to->buf + ((scale == 0 && intg0 == 0) ? 1 : intg0 + frac0); - dec1 *end= to->buf + len; - - while (buf < end) - *buf++=0; - } if (*buf1 >= DIG_BASE) { carry=1; @@ -1633,6 +1615,7 @@ decimal_round(const decimal_t *from, decimal_t *to, int scale, } *buf1=1; to->intg++; + intg0++; } } else @@ -1654,6 +1637,24 @@ decimal_round(const decimal_t *from, decimal_t *to, int scale, } } } + /* + In case we're rounding e.g. 1.5e9 to 2.0e9, the decimal_digit_t's inside + the buffer are as follows. + + Before <1, 5e8> + After <2, 5e8> + + Hence we need to set the 2nd field to 0. + The same holds if we round 1.5e-9 to 2e-9. + */ + if (frac0 < frac1) + { + dec1 *buf= to->buf + ((scale == 0 && intg0 == 0) ? 1 : intg0 + frac0); + dec1 *end= to->buf + len; + + while (buf < end) + *buf++=0; + } /* Here we check 999.9 -> 1000 case when we need to increase intg */ first_dig= to->intg % DIG_PER_DEC1; |