[llvm] r364920 - [APIntTest] multiplicativeInverse(): clarify test
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 06:21:17 PDT 2019
Author: lebedevri
Date: Tue Jul 2 06:21:17 2019
New Revision: 364920
URL: http://llvm.org/viewvc/llvm-project?rev=364920&view=rev
Log:
[APIntTest] multiplicativeInverse(): clarify test
Clarify that multiplicative inverse exists for all odd numbers,
and does not exist for all even numbers (including 0).
Modified:
llvm/trunk/unittests/ADT/APIntTest.cpp
Modified: llvm/trunk/unittests/ADT/APIntTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APIntTest.cpp?rev=364920&r1=364919&r2=364920&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APIntTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APIntTest.cpp Tue Jul 2 06:21:17 2019
@@ -2527,10 +2527,13 @@ TEST(APIntTest, MultiplicativeInverseExa
.multiplicativeInverse(APInt::getSignedMinValue(BitWidth + 1))
.trunc(BitWidth);
APInt One = V * MulInv;
- EXPECT_TRUE(MulInv.isNullValue() || One.isOneValue())
- << " bitwidth = " << BitWidth << ", value = " << Value
- << ", computed multiplicative inverse = " << MulInv
- << ", value * multiplicative inverse = " << One << " (should be 1)";
+ if (!V.isNullValue() && V.countTrailingZeros() == 0) {
+ // Multiplicative inverse exists for all odd numbers.
+ EXPECT_TRUE(One.isOneValue());
+ } else {
+ // Multiplicative inverse does not exist for even numbers (and 0).
+ EXPECT_TRUE(MulInv.isNullValue());
+ }
}
}
}
More information about the llvm-commits
mailing list