llvm.org GIT mirror llvm / 123cdac
[APIntTest] multiplicativeInverse(): clarify test Clarify that multiplicative inverse exists for all odd numbers, and does not exist for all even numbers (including 0). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364920 91177308-0d34-0410-b5e6-96231b3b80d8 Roman Lebedev a month ago
1 changed file(s) with 7 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
25262526 .multiplicativeInverse(APInt::getSignedMinValue(BitWidth + 1))
25272527 .trunc(BitWidth);
25282528 APInt One = V * MulInv;
2529 EXPECT_TRUE(MulInv.isNullValue() || One.isOneValue())
2530 << " bitwidth = " << BitWidth << ", value = " << Value
2531 << ", computed multiplicative inverse = " << MulInv
2532 << ", value * multiplicative inverse = " << One << " (should be 1)";
2529 if (!V.isNullValue() && V.countTrailingZeros() == 0) {
2530 // Multiplicative inverse exists for all odd numbers.
2531 EXPECT_TRUE(One.isOneValue());
2532 } else {
2533 // Multiplicative inverse does not exist for even numbers (and 0).
2534 EXPECT_TRUE(MulInv.isNullValue());
2535 }
25332536 }
25342537 }
25352538 }