[PPL-devel] Re: Question about converting integers in PPL

Roberto Bagnara bagnara at cs.unipr.it
Tue Jul 23 08:20:40 CEST 2002


Martin Rohde wrote:
> I have (simple) a question about using PPL 0.4:
> 
> I cannot find how to convert a coefficient (of a constraint or generator)
> to the normal integer type. In my code I do the following; c1 is a
> constraint which is defined earlier in the code. Now I try to convert a
> coefficient with
> 
> c1_int = mpz_get_si(c1.coefficient(Variable(0)))
> 
> but this doesn't work, probably because the coefficient is not of the
> regular gmp format (c1_int is a standard integer)
> 
> How can I convert coefficients to 'normal' integers (or double integers)?

Dear Martin,

if you want to go the safe way (something I would highly recommend),
you should use a fragment like the following (perhaps incapsulating
this functionality into a convenience function):

   const Integer& c1_coeff_0 = c1.coefficient(Variable(0));
   if (c1_coeff_0.fits_sint_p()) {
     long c1_int = c1_coeff_0.get_si();
     // Use c1_int.
   }
   else {
     // c1_coeff_0 exceeds the range of signed integers.
     // Do something else.
   }

The chapter of GMP's manual "C++ Class Interface"
will tell you more about the operations supported
by mpz_class (which is the same as Parma_Polyhedra_Library::Integer).

By the way, thanks to your message we have discovered that
the user's manual does not give any indication that
Parma_Polyhedra_Library::Integer is the same as GMP's mpz_class.
This will be fixed in future releases.
Thanks!

     Roberto

-- 
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara at cs.unipr.it




More information about the PPL-devel mailing list