Contributing to GMP
bodrato at mail.dm.unipi.it
Sun Feb 23 23:43:05 UTC 2020
Il Mar, 18 Febbraio 2020 8:54 pm, Anders Andersson ha scritto:
> On Tue, Feb 18, 2020 at 1:09 PM Michele Guerini Rocco
>> Anyway, I had to compute the natural logarithm of a natural number to
>> arbitrary precision, so I wrote a `mpq_log_ui` function to do that,
>> something which GMP doesn't provide.
> Everything else dealing with rational numbers works with *exact*
> numbers, and it seems to me that a log_ui will rarely be exact.
I agree, a log_ui function does not belong to the current mpq_t interface.
But maybe it would be interesting to write some mpq_ functions giving
inexact results... If it is possible to return a fraction that is a good
result as a fraction. I mean a result that can be interesting for someone
working with rationals, more interesting than an approximation obtained
with the floating-point paradigm and converted back to a fraction...
E.g. the attached code computes the square root of a fraction. It returns
either the exact result, or a result with the denominator limited by a
given number of bits.
For A=1068966896/340262731, it returns R=2887206440/1628931799.
Where we have 1628931799 < 2^32, and |A-R^2| < 2^-63.
The code is simple. It computes the continued fraction for the square root
of a fraction, term by term, and does not exploit the periodicity nor any
other trick to obtain balanced multiplications... I mean, it's not fast.
Might inexact functions on rationals, like this one, be useful to someone?
If made faster, of course.
Anyway, extending the rational interface in a coherent way, to add also
inexact functions, seems difficult.
Some example functions may belong to the demo directory :-)
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 3193 bytes
Desc: not available
More information about the gmp-discuss