[APIntTest] multiplicativeInverse(): clarify test
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 2 Jul 2019 13:21:17 +0000 (13:21 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 2 Jul 2019 13:21:17 +0000 (13:21 +0000)
Clarify that multiplicative inverse exists for all odd numbers,
and does not exist for all even numbers (including 0).

llvm-svn: 364920

llvm/unittests/ADT/APIntTest.cpp

index 6456066..4ab79e4 100644 (file)
@@ -2527,10 +2527,13 @@ TEST(APIntTest, MultiplicativeInverseExaustive) {
               .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());
+      }
     }
   }
 }