Below is the code in C++,
Num *= other.Den;
Den *= other.Num;
if (Den.isNegative()) {
Num = -Num;
Den = -Den;
}
assert(Den.isStrictlyPositive());
where Num and Den are of type LLVM::APInt.
For some reason I am getting the assertion failed. I have checked if the Denominator is negative explicitly and turned it positive. Can someone please let me in what scenario in this code, the assertion can fail? When I run my code against test case it fails. The test case is very large, and I have not been successful in cornering a particular case. The above code is a part of my algorithm which is doing some other job.
Here is the implementation of isStrictlyPositive. It is using the LLVM library file APInt.h.
bool isStrictlyPositive() const {
return isNonNegative() && !!*this;
}
bool isNonNegative() const {
return !isNegative();
}
I’m basing this off the following assumptions:
isNegativeis < 0Given the snippet you quoted, the function
isStrictlyPositiveboils down to:Which is equivalent to:
!!*thisis equivalent to!(!*this)which is equivalent to!(*this==0)which is equivalent to*this!=0, so the expression is:Which can be simplified to:
Which is really just:
So, your issue is that
Denis0and is therefore not negative and not strictly positive.