summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorunknown <serg@serg.mylan>2004-12-06 13:06:52 +0100
committerunknown <serg@serg.mylan>2004-12-06 13:06:52 +0100
commit66531aa491adf1e1400255f0f4bb88cd0bada219 (patch)
tree9d4eec4a62f1b3f53732a0f22775bdc30e596e16 /strings
parentf09c8b35f4d36de42be7ced51f1200727385ce79 (diff)
downloadmariadb-git-66531aa491adf1e1400255f0f4bb88cd0bada219.tar.gz
strings/decimal.c
handle test_ro(".999", 0, HALF_UP, "1"); strings/decimal.c: handle test_ro(".999", 0, HALF_UP, "1");
Diffstat (limited to 'strings')
-rw-r--r--strings/decimal.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/strings/decimal.c b/strings/decimal.c
index 224d75f6844..6b2982d8d8f 100644
--- a/strings/decimal.c
+++ b/strings/decimal.c
@@ -901,19 +901,26 @@ int decimal_round(decimal *from, decimal *to, int scale, decimal_round_mode mode
if (scale >= from->frac)
goto done; /* nothing to do */
- DBUG_ASSERT(frac0+intg0 > 0);
buf0+=intg0+frac0-1;
buf1+=intg0+frac0-1;
if (scale == frac0*DIG_PER_DEC1)
{
+ DBUG_ASSERT(frac0+intg0 >= 0);
x=buf0[1]/DIG_MASK;
if (x > round_digit ||
- (round_digit == 5 && x == 5 && (mode == HALF_UP || *buf0 & 1)))
- (*buf1)++;
+ (round_digit == 5 && x == 5 && (mode == HALF_UP ||
+ (frac0+intg0 > 0 && *buf0 & 1))))
+ {
+ if (frac0+intg0>0)
+ (*buf1)++;
+ else
+ *(++buf1)=DIG_BASE;
+ }
}
else
{
int pos=frac0*DIG_PER_DEC1-scale-1;
+ DBUG_ASSERT(frac0+intg0 > 0);
x=*buf1 / powers10[pos];
y=x % 10;
if (y > round_digit ||
@@ -942,7 +949,7 @@ int decimal_round(decimal *from, decimal *to, int scale, decimal_round_mode mode
scale=frac0*DIG_PER_DEC1;
error=E_DEC_TRUNCATED; /* XXX */
}
- for (buf1=to->buf+frac0+intg0; buf1 > to->buf; buf1--)
+ for (buf1=to->buf+intg0+max(frac0,0); buf1 > to->buf; buf1--)
{
buf1[0]=buf1[-1];
}
@@ -2103,6 +2110,9 @@ main()
test_ro("15.4",-1,HALF_UP,"20");
test_ro("-15.4",-1,HALF_UP,"-20");
test_ro("5.4",-1,HALF_UP,"10");
+ test_ro(".999", 0, HALF_UP, "1");
+ memset(buf2, 33, sizeof(buf2));
+ test_ro("999999999", -9, HALF_UP, "1000000000");
test_ro("15.1",0,HALF_EVEN,"15");
test_ro("15.5",0,HALF_EVEN,"16");
test_ro("14.5",0,HALF_EVEN,"14");