-4

All variables in my program use the following datatype

typedef long long ll;

I installed GMP and tried to do this:

typedef mpz_class ll;

and I tried

typedef mpz_t ll;

But it won't compile, usually with tons of "invalid operator" errors. Is there any easier way to translate things over?

Example error:

ll a = sqrt(static_cast<double>(n/2));

invalid static_cast from type __gmp_expr<__mpz_struct[1], __gmp_binary_expr<mpz_class, long int, __gmp_binary_divides> >' to typedouble'

another one:

count-=myArr[m];

no match for 'operator[]' in 'myArr[m]'

it also won't let me do

 mpz_t count;
 count = (x*x-1);

where x is a long long

MyNameIsKhan
  • 2,594
  • 8
  • 36
  • 56

1 Answers1

2

First of all, mpz_t does not have any operator overloading because it's a C struct, not a C++ class. Next, mpz_class behaves sort of like an integer because it has some basic operator overloading. However, it absolutely does not work as a drop-in replacement for some other kind of integer value. You will have to go through your program and fix all the errors by replacing your current code with next code that will work on mpz_class values. There is no trivial way to do this: you will have to bite the bullet and learn how to use GMP effectively.

Alternately, you could try to use somthing like CLN or another library that attempts to give a closer approximation to a big number drop-in replacement for C++. There is no library I am aware of that does this completely or even very well.

wjl
  • 7,519
  • 2
  • 32
  • 41