summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-05-22 01:09:48 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-05-22 01:09:48 +0000
commita7a2a3635f2fbe46d7d9074798e79e853f69d40b (patch)
treea8eff441253ba0dd28644172d2aa310d9b71bd0f /unittests
parent6b07bc604ee891185435c040f0a872774c64af29 (diff)
downloadllvm-a7a2a3635f2fbe46d7d9074798e79e853f69d40b.tar.gz
llvm-a7a2a3635f2fbe46d7d9074798e79e853f69d40b.tar.bz2
llvm-a7a2a3635f2fbe46d7d9074798e79e853f69d40b.tar.xz
fix the quotient returned by sdivrem() for the case when LHS is negative and RHS is positive
based on a patch by Preston Briggs, with some modifications git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157231 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/APIntTest.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp
index 89b8aa94e4..49d7e703de 100644
--- a/unittests/ADT/APIntTest.cpp
+++ b/unittests/ADT/APIntTest.cpp
@@ -171,6 +171,34 @@ TEST(APIntTest, i1) {
EXPECT_EQ(zero, neg_one.srem(one));
EXPECT_EQ(zero, neg_one.urem(one));
EXPECT_EQ(zero, one.srem(neg_one));
+
+ // sdivrem
+ {
+ APInt q(8, 0);
+ APInt r(8, 0);
+ APInt one(8, 1);
+ APInt two(8, 2);
+ APInt nine(8, 9);
+ APInt four(8, 4);
+
+ EXPECT_EQ(nine.srem(two), one);
+ EXPECT_EQ(nine.srem(-two), one);
+ EXPECT_EQ((-nine).srem(two), -one);
+ EXPECT_EQ((-nine).srem(-two), -one);
+
+ APInt::sdivrem(nine, two, q, r);
+ EXPECT_EQ(four, q);
+ EXPECT_EQ(one, r);
+ APInt::sdivrem(-nine, two, q, r);
+ EXPECT_EQ(-four, q);
+ EXPECT_EQ(-one, r);
+ APInt::sdivrem(nine, -two, q, r);
+ EXPECT_EQ(-four, q);
+ EXPECT_EQ(one, r);
+ APInt::sdivrem(-nine, -two, q, r);
+ EXPECT_EQ(four, q);
+ EXPECT_EQ(-one, r);
+ }
}
TEST(APIntTest, fromString) {