14 #ifndef MLIR_ANALYSIS_PRESBURGER_FRACTION_H
15 #define MLIR_ANALYSIS_PRESBURGER_FRACTION_H
21 namespace presburger {
49 assert(
num %
den == 0 &&
"Get as integer called on non-integral fraction!");
53 llvm::raw_ostream &
print(llvm::raw_ostream &os)
const {
54 return os <<
"(" <<
num <<
"/" <<
den <<
")";
105 assert(f.
den > 0 &&
"denominator of fraction must be positive!");
135 return (f.
num / f.
den) + (rem > f.
den / 2);
This class provides support for multi-precision arithmetic.
LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt gcd(const MPInt &a, const MPInt &b)
llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const Fraction &x)
MPInt round(const Fraction &f)
Fraction & operator-=(Fraction &x, const Fraction &y)
Fraction operator+(const Fraction &x, const Fraction &y)
LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt ceilDiv(const MPInt &lhs, const MPInt &rhs)
bool operator==(const Fraction &x, const Fraction &y)
bool operator>(const Fraction &x, const Fraction &y)
bool operator<(const Fraction &x, const Fraction &y)
int compare(const Fraction &x, const Fraction &y)
Three-way comparison between two fractions.
bool operator>=(const Fraction &x, const Fraction &y)
Fraction reduce(const Fraction &f)
Fraction operator-(const Fraction &x)
bool operator<=(const Fraction &x, const Fraction &y)
Fraction & operator*=(Fraction &x, const Fraction &y)
Fraction abs(const Fraction &f)
MPInt ceil(const Fraction &f)
Fraction & operator/=(Fraction &x, const Fraction &y)
bool operator!=(const Fraction &x, const Fraction &y)
Fraction & operator+=(Fraction &x, const Fraction &y)
Fraction operator*(const Fraction &x, const Fraction &y)
MPInt floor(const Fraction &f)
Fraction operator/(const Fraction &x, const Fraction &y)
LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt floorDiv(const MPInt &lhs, const MPInt &rhs)
Include the generated interface declarations.
A class to represent fractions.
Fraction()=default
Default constructor initializes the represented rational number to zero.
MPInt getAsInteger() const
Fraction(const MPInt &num, int64_t den)
Overloads for passing literals.
Fraction(int64_t num, const MPInt &den=MPInt(1))
Fraction(int64_t num, int64_t den)
MPInt num
The numerator and denominator, respectively.
llvm::raw_ostream & print(llvm::raw_ostream &os) const
Fraction(const MPInt &oNum, const MPInt &oDen=MPInt(1))
Construct a Fraction from a numerator and denominator.