Marco Bodrato bodrato at
Fri Aug 21 05:51:36 UTC 2015


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))

> > (We might consider adding mpf_cmp_z too, at least in a simple-minded
> > manner, to keep the GMP interface as orthogonal as possible.)

> Adding new mpf_t functions might confuse the message that people should
> use mpfr...

We can silently add it to the manual without claiming it in the release
announce :-)

A tenth of lines of code should be enough, shouldn't it?

mpf_cmp_z (mpf_srcptr u, mpz_srcptr v) __GMP_NOTHROW
  mpf_t vf;
  mp_size_t size;

  SIZ (vf) = size = SIZ (v);
  EXP (vf) = size = ABS (size);
  /* PREC (vf) = size; */
  PTR (vf) = PTR (v);

  return mpf_cmp (u, vf);

Best regards,


More information about the gmp-devel mailing list