summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2014-10-07 10:53:43 +0200
committerSergei Golubchik <sergii@pisem.net>2014-10-07 10:53:43 +0200
commitd2e808025aec75fbb0ee37935a862d137a03a9c3 (patch)
tree55fb94cdb7090e413999b5dbdcbfe438b53702e9
parent7989c62bc0c4b74f866367cc9337444913178a0d (diff)
downloadmariadb-git-d2e808025aec75fbb0ee37935a862d137a03a9c3.tar.gz
fixes for decimal type
-rw-r--r--mysql-test/r/type_newdecimal.result6
-rw-r--r--mysql-test/t/type_newdecimal.test9
-rw-r--r--strings/decimal.c6
3 files changed, 20 insertions, 1 deletions
diff --git a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result
index 7e030591fcd..1730ef152e3 100644
--- a/mysql-test/r/type_newdecimal.result
+++ b/mysql-test/r/type_newdecimal.result
@@ -1988,3 +1988,9 @@ SELECT d1 * d2 FROM t1;
d1 * d2
0
DROP TABLE t1;
+select 0.000000000000000000000000000000000000000000000000001 mod 1;
+0.000000000000000000000000000000000000000000000000001 mod 1
+0.000000000000000000000000000000
+select 0.0000000001 mod 1;
+0.0000000001 mod 1
+0.0000000001
diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test
index bf7e3794a19..5dcbfa15c2f 100644
--- a/mysql-test/t/type_newdecimal.test
+++ b/mysql-test/t/type_newdecimal.test
@@ -1570,3 +1570,12 @@ SELECT d1 * d2 FROM t1;
DROP TABLE t1;
+#
+# Test for Bug#18469276: MOD FOR SMALL DECIMALS FAILS
+#
+select 0.000000000000000000000000000000000000000000000000001 mod 1;
+
+#
+# incorrect result
+#
+select 0.0000000001 mod 1;
diff --git a/strings/decimal.c b/strings/decimal.c
index 49b12f14dbf..8d6877a24ec 100644
--- a/strings/decimal.c
+++ b/strings/decimal.c
@@ -127,7 +127,6 @@ typedef longlong dec2;
#define DIG_BASE 1000000000
#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};
static const int dig2bytes[DIG_PER_DEC1+1]={0, 1, 1, 2, 2, 3, 3, 4, 4, 4};
@@ -136,6 +135,11 @@ static const dec1 frac_max[DIG_PER_DEC1-1]={
999900000, 999990000, 999999000,
999999900, 999999990 };
+static inline int ROUND_UP(int x)
+{
+ return (x + (x > 0 ? 1 : -1) * (DIG_PER_DEC1 - 1)) / DIG_PER_DEC1;
+}
+
#ifdef HAVE_valgrind
#define sanity(d) DBUG_ASSERT((d)->len > 0)
#else