14 #ifndef MLIR_ANALYSIS_PRESBURGER_FRACTION_H
15 #define MLIR_ANALYSIS_PRESBURGER_FRACTION_H
17 #include "llvm/ADT/DynamicAPInt.h"
18 #include "llvm/Support/raw_ostream.h"
21 namespace presburger {
22 using llvm::DynamicAPInt;
34 Fraction(
const DynamicAPInt &oNum,
const DynamicAPInt &oDen = DynamicAPInt(1))
52 assert(
num %
den == 0 &&
"Get as integer called on non-integral fraction!");
56 llvm::raw_ostream &
print(llvm::raw_ostream &os)
const {
57 return os <<
"(" <<
num <<
"/" <<
den <<
")";
108 assert(f.
den > 0 &&
"denominator of fraction must be positive!");
137 DynamicAPInt rem = f.
num % f.
den;
138 return (f.
num / f.
den) + (rem > f.
den / 2);
llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const Fraction &x)
Fraction & operator-=(Fraction &x, const Fraction &y)
Fraction operator+(const Fraction &x, const Fraction &y)
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.
DynamicAPInt floor(const Fraction &f)
bool operator>=(const Fraction &x, const Fraction &y)
DynamicAPInt ceil(const Fraction &f)
Fraction reduce(const Fraction &f)
Fraction operator-(const Fraction &x)
bool operator<=(const Fraction &x, const Fraction &y)
DynamicAPInt round(const Fraction &f)
Fraction & operator*=(Fraction &x, const Fraction &y)
Fraction abs(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)
Fraction operator/(const Fraction &x, const Fraction &y)
Include the generated interface declarations.
A class to represent fractions.
Fraction()=default
Default constructor initializes the represented rational number to zero.
Fraction(int64_t num, const DynamicAPInt &den=DynamicAPInt(1))
Fraction(const DynamicAPInt &oNum, const DynamicAPInt &oDen=DynamicAPInt(1))
Construct a Fraction from a numerator and denominator.
DynamicAPInt getAsInteger() const
Fraction(const DynamicAPInt &num, int64_t den)
Overloads for passing literals.
Fraction(int64_t num, int64_t den)
DynamicAPInt num
The numerator and denominator, respectively.
llvm::raw_ostream & print(llvm::raw_ostream &os) const