Search code examples
c++gmp

Using ceil in C++ GMP


 L=ceil((sqrt(v-4*N)-1)/4)-1

where V and N are mpz_class variables.

For some reason this throws an error that opens up gmpxx.h and has a problem with

inline void __gmp_set_expr(mpz_ptr z, const __gmp_expr<mpz_t, T> &expr)
{
  expr.eval(z);
}

How do I do this ceil properly?


Solution

  • I'm not familiar with the C++ interface, but I think sqrt() of an mpz_class variable will return an mpz_class result. There is no point in applying ceil() to an integer. You will need to use mpf_class to get a floating point result from sqrt() and then ceil() should work (but return an mpf_class).