summaryrefslogtreecommitdiff
path: root/strings/decimal.c
diff options
context:
space:
mode:
authorunknown <serg@serg.mylan>2005-02-20 16:55:11 +0100
committerunknown <serg@serg.mylan>2005-02-20 16:55:11 +0100
commitf4ac869b8833657ce5313697b817e8789355021d (patch)
treeae6ce4f47b80c2c1f64994adcf2e2400a91f9e1f /strings/decimal.c
parent91cc139a17e11e2ea25761d66ecc735f2d777c47 (diff)
downloadmariadb-git-f4ac869b8833657ce5313697b817e8789355021d.tar.gz
underflow in decimal_round fixed
Diffstat (limited to 'strings/decimal.c')
-rw-r--r--strings/decimal.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/strings/decimal.c b/strings/decimal.c
index 212bd7204f6..28c6ace658f 100644
--- a/strings/decimal.c
+++ b/strings/decimal.c
@@ -14,7 +14,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#line __LINE__ "decimal.c"
+#line 18 "decimal.c"
/*
=======================================================================
@@ -113,8 +113,8 @@ typedef longlong dec2;
#define DIG_PER_DEC1 9
#define DIG_MASK 100000000
#define DIG_BASE 1000000000
-#define DIG_MAX 999999999
-#define DIG_BASE2 LL(1000000000000000000)
+#define DIG_MAX (DIG_BASE-1)
+#define DIG_BASE2 ((dec2)DIG_BASE * (dec2)DIG_BASE)
#define ROUND_UP(X) (((X)+DIG_PER_DEC1-1)/DIG_PER_DEC1)
static const dec1 powers10[DIG_PER_DEC1+1]={
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
@@ -1415,6 +1415,11 @@ int decimal_round(decimal *from, decimal *to, int scale, decimal_round_mode mode
else
*(++buf1)=DIG_BASE;
}
+ else if (frac0+intg0==0)
+ {
+ decimal_make_zero(to);
+ return E_DEC_OK;
+ }
}
else
{
@@ -2666,11 +2671,12 @@ int main()
test_md("234.567","10.555","2.357", 0);
test_md("-234.567","10.555","-2.357", 0);
test_md("234.567","-10.555","2.357", 0);
- if (full)
+ c.buf[1]=0x3ABECA;
+ test_md("99999999999999999999999999999999999999","3","0", 0);
+ if (c.buf[1] != 0x3ABECA)
{
- c.buf[1]=0x3ABECA;
- test_md("99999999999999999999999999999999999999","3","0", 0);
- printf("%X\n", c.buf[1]);
+ printf("%X - overflow\n", c.buf[1]);
+ exit(1);
}
printf("==== decimal2bin/bin2decimal ====\n");
@@ -2741,6 +2747,16 @@ int main()
test_ro("999999999999999999999.999", 0, CEILING,"1000000000000000000000", 0);
test_ro("-999999999999999999999.999", 0, FLOOR,"-1000000000000000000000", 0);
+ b.buf[0]=DIG_BASE+1;
+ b.buf++;
+ test_ro(".3", 0, HALF_UP, "0", 0);
+ b.buf--;
+ if (b.buf[0] != DIG_BASE+1)
+ {
+ printf("%d - underflow\n", b.buf[0]);
+ exit(1);
+ }
+
printf("==== max_decimal ====\n");
test_mx(1,1,"0.9");
test_mx(1,0,"9");