Compilation problem

Mathieu Dutour mathieu.dutour at gmail.com
Sun Feb 26 15:53:05 CET 2023


Hello,

I have some compilation error with following code:
----------
#include "gmpxx.h"

template <typename T> T T_abs(T const &eVal) {
  if (eVal > 0)
    return eVal;
  T fVal = -eVal;
  return fVal;
}

int main(int argc, char *argv[]) {
  using T = mpq_class;
  T val1 = argc;
  T val2 = 2 * argc;
  T valN = T_abs(val1 - val2);
}
----------
which cause following error:
GmpTest.cpp:7:5: error: no viable conversion from '__gmp_expr<[...],
__gmp_unary_expr<__gmp_expr<__mpq_struct[1],
__gmp_binary_expr<__gmp_expr<mpq_t, mpq_t>, __gmp_expr<mpq_t, mpq_t>,
__gmp_binary_minus>>, __gmp_unary_minus>>' to '__gmp_expr<[...],
__gmp_binary_expr<__gmp_expr<mpq_t, mpq_t>, __gmp_expr<mpq_t, mpq_t>,
__gmp_binary_minus>>'
  T fVal = -eVal;

Is it a mistake on my side or is there some missing conversion in gmpxx.h?

  Mathieu


More information about the gmp-discuss mailing list