
-------- Original Message -------- Subject: Re: Bug affecting mpq_class::get_num() and mpq_class::get_den()? Date: Wed, 12 Jun 2002 10:25:03 +1000 From: Kevin Ryde user42@zip.com.au To: gerardo.ballabio@unimib.it (Ballabio Gerardo - Dip. di Scienza dei Materiali) CC: Roberto Bagnara bagnara@cs.unipr.it, Torbjorn Granlund tege@swox.se References: 87k7p9bdqi.fsf@zip.com.au 20020610122024.C4790@nettunio.mater.unimib.it
gerardo.ballabio@unimib.it (Ballabio Gerardo - Dip. di Scienza dei Materiali) writes:
but I don't know very much about the internals of mpz_t and mpq_t, and I'm not sure that such "symlinking" can be done
An mpq_t is just two mpz_t's, nothing more. mpq_numref and mpq_denref give pointers to the respective fields. Would it work to cast to an "mpz_class *" or "mpz_class &"? Or would that be too nasty.
(actually, I looked into gmp.h, but I'm quite confused about mpz_t being defined as "typedef __mpz_struct mpz_t[1];").
That trickery means when mpz_t is used to define a variable, it gets space for one __mpz_struct, but if mpz_t is used as a function parameter then it's just a pointer which is passed, giving "call by reference".
Otherwise, I can only suggest to leave the code as it is, and to change the documentation like this:
Thanks, I'll do that for now, and maybe put a note in the limitations section about why.