[Mlir-commits] [mlir] [MLIR][Presburger] Add LLL basis reduction (PR #75565)

Arjun P llvmlistbot at llvm.org
Sun Dec 17 11:57:42 PST 2023


================
@@ -124,6 +129,14 @@ inline Fraction operator-(const Fraction &x, const Fraction &y) {
   return reduce(Fraction(x.num * y.den - x.den * y.num, x.den * y.den));
 }
 
+// Find the integer nearest to a given fraction.
+inline MPInt round(const Fraction &f) {
+  MPInt rem = f.num % f.den;
+  if (rem < Fraction(f.den, 2))
+    return (f.num - rem) / f.den;
+  return (f.num + f.den - rem) / f.den;
----------------
Superty wrote:

Sorry I just realized this can be further simplified

`return f.num/f.den + (f.num > f.den/2);`

https://github.com/llvm/llvm-project/pull/75565


More information about the Mlir-commits mailing list