"The set of mpq functions is quite small." Is this by design?

Torbjörn Granlund tg at gmplib.org
Sat Aug 11 11:50:07 UTC 2018


Anders Andersson <pipatron at gmail.com> writes:

  Hi! I tend to use the rational functions in GMP a lot, and quoting
  from the documentation: The set of mpq functions is quite small.

  I was wondering if this is by design or if the developers would
  welcome an extension of the API to cover some more common cases that
  I've found while using it?

Use cases which suggest some shortcoming of GMP are interesting!

  I'm mostly missing arithmetic with native integers (think mpq_mul_ui)
  and raw I/O functions. These are all trivial to implement but having
  them in the API could perhaps enable some optimizations when it is
  known that one operand is always small.

"Raw" I/O function would need to define a file format.  I consider the
file format of the current mpz_*_raw function to be poor, so before even
considering raw I/O extension of mpq or mpf, a better file format should
be considered.

In the meantime, using mpz_*_raw in the numerator and denominator
separetely might be what you want to do.  Or else mpz_export/import
followed by some system I/O operation.

Perhaps mpq_mul_ui would make sense.  It would require a gcd of the ui
argument with the denominator.

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


More information about the gmp-discuss mailing list