[Mlir-commits] [mlir] [MLIR][Presburger] Implement arithmetic operations (/, +, -) and printing for Fractions (PR #65310)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Sep 5 06:48:07 PDT 2023


================
@@ -30,15 +30,15 @@ struct Fraction {
   Fraction() = default;
 
   /// Construct a Fraction from a numerator and denominator.
-  Fraction(const MPInt &oNum, const MPInt &oDen) : num(oNum), den(oDen) {
+  Fraction(const MPInt &oNum, const MPInt &oDen = MPInt(1)) : num(oNum), den(oDen) {
     if (den < 0) {
       num = -num;
       den = -den;
     }
   }
   /// Overloads for passing literals.
-  Fraction(const MPInt &num, int64_t den) : Fraction(num, MPInt(den)) {}
-  Fraction(int64_t num, const MPInt &den) : Fraction(MPInt(num), den) {}
+  Fraction(const MPInt &num, int64_t den = 1) : Fraction(num, MPInt(den)) {}
+  Fraction(int64_t num, const MPInt &den = MPInt(1)) : Fraction(MPInt(num), den) {}
   Fraction(int64_t num, int64_t den) : Fraction(MPInt(num), MPInt(den)) {}
----------------
Abhinav271828 wrote:

> Please also add the default here for consistency.

This causes an "ambiguous conversion" error if you write, say, `Fraction(0)` (because the second and third constructors both apply).

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


More information about the Mlir-commits mailing list