mpq_cmp_z

Torbjörn Granlund tg at gmplib.org
Sun Aug 16 21:50:52 UTC 2015


"Marco Bodrato" <bodrato at mail.dm.unipi.it> writes:

  Ciao Vincent,
  
  On Sat, August 15, 2015 12:37 pm, Vincent Delecroix wrote:
  > rationals. We often have to compare integers with rationals and I came
  > to the conclusion that it would be convenient to have a GMP function
  >
  >     int mpq_cmp_z(mpq_t, mpz_t)
  
  Makes sense.
  
  > If you think that it would be a good addition, you might have a look in
  > the attached patch that was tested on the development version of GMP.
  
  I already have a similar function, I obtained it by pruning the mpq_cmp
  function, and you likely did the same, with an older version...
  
  I was waiting to propose, and commit it, because I'd like to overhaul many
  comparison function, maybe uniformly defining functions to test
  equality... and so on. But if you particularly need this function I think
  we can start by adding it.
  
  Comparing your code with mine, I see you added a couple of lines:
    if (!mpz_cmp_ui(mpq_denref(op), 1))  /* denominator 1 */
          return mpz_cmp(mpq_numref(op), v);
  I'll test and add something equivalent.
  
We might consider some code sharing between the mpq_cmp and this
function, they look very similar.

We might even just put the mpz in stack allocated mpq structure and fall
into mpq_cmp with a tail call.

-- 
Torbjörn
Please encrypt, key id 0xC8601622


More information about the gmp-devel mailing list