mini-gmp and mpq

Marco Bodrato bodrato at mail.dm.unipi.it
Mon Apr 30 08:06:56 UTC 2018


Ciao,

Il Lun, 30 Aprile 2018 4:10 am, Bradley Lucier ha scritto:
>> On Apr 29, 2018, at 9:02 PM, Marco Bodrato <bodrato at mail.dm.unipi.it>
>>> Il Dom, 29 Aprile 2018 8:24 pm, Bradley Lucier ha scritto:

> Looks good.  The important case is when a=b, but I just realized that the
> test can be refined to when the denominator of a is the denominator of b.

Interesting observation. But, do you think it's worth replacing
  if (a != b)
with
  if (mpz_cmp (mpq_denref (a), mpq_denref (b)))
?

Maybe something similar for the full library?

>>> mpq_canonicalize (mpq_t r)

>> This function is not static, as you can see.

> True.  I never found a need to call a canonicalize function for rationals.

Our test suite uses it for e.g.

static void
_mpq_set_zz (mpq_t q, mpz_t n, mpz_t d)
{
  mpq_set_num (q, n);
  mpq_set_den (q, d);
  mpq_canonicalize (q);
}

> The code is fine, it is clear.

...but why it correctly works in the reuse case: mpq_div(r,a,r) or even
mpq_div(r,r,r), is not completely obvious. We should at least add a check
for that in the test-suite...

Ĝis,
m

-- 
http://bodrato.it/papers/



More information about the gmp-devel mailing list