mpq_cmp_z
Marc Glisse
marc.glisse at inria.fr
Fri Aug 21 06:04:25 UTC 2015
On Fri, 21 Aug 2015, Marco Bodrato wrote:
> On Thu, August 20, 2015 9:56 am, Marc Glisse wrote:
>>> Is casting an mpz to an mpq, then accessing only the NUM() part of it,
>>> portable?
>
>> From what I understand of the aliasing model currently used by gcc, to
>> be safe, in the function using it, we should have:
>> mpz_srcptr op2n = NUM(op2);
>> and then use SIZ(op2n) instead of directly SIZ(NUM(op2)). The reason is
>
>> "x=op2->_mp_den._mp_size" promises that op2 points to a __mpq_struct
>> while "x=op2n->_mp_size" only promises a __mpz_struct (and gcc folds *&
>
> Maybe we can "promise" the right type, by adding an explicit cast?
> SIZ((mpz_srcptr) NUM(op2))
I think that cast would be ignored, you really want them in separate
expressions.
Another thing I forgot: computing DEN(op2) could also be illegal unless
the layout of __mpq_struct is the same as __mpz_struct[2], in which case
we are computing the "past-the-end" pointer of the mpz_t, which is ok.
Anyway, I was just trying to think of potential issues with the code, feel
free to ignore it as long as nobody reports an issue with it.
--
Marc Glisse
More information about the gmp-devel
mailing list