gmp 4.1 documentation improvement suggestions

Kevin Ryde
Mon, 09 Dec 2002 10:47:08 +1000

Serge Winitzki <> writes:
> I decided to use mpz_get_d_2exp instead of mpz_sizeinbase because there
> wasn't an mpf_sizeinbase and because it seemed that mpz_sizeinbase is
> not as efficient since needs to give me the size in any base, not just
> in base 2. Maybe I'm wrong and mpz_sizeinbase is optimized for base 2;  

Yes, it recognises power-of-2 bases and gives an exact answer quickly.

> Another issue I wanted to mention is related to precision control in
> calculations. Suppose we are using functions such as mpf_add(x,x,y);  
> by default the target precision is taken from the first argument "x", so
> "x+y" is evaluated to the same precision as "x". However there are
> situations when the precision of "x" is lower than the precision of the
> result, for example, if x=0.001 (one significant bit) and y=1.000 (four
> significant bits). It is not obvious to a beginner GMP user that this
> situation will sometimes arise and lead to a loss of precision.

Well, gmp has no way to know the actual error range of a particular
value you store in an mpf_t.  That range is no doubt a function of the
calculation thus far performed, and perhaps of the original inputs.

> I've been using GMP 4.0.1 and just found out that GMP 4.1 has a new mpfr
> facility that incorporates precision tracking.

See also

> However, I couldn't find
> documentation about how the precision tracking is done, and reading the
> source code is too time-consuming for me.

It still doesn't track anything, but it does give guarantees about
rounding of results.

> I just finished drafting my
> own simple precision tracking implementation for our Yacas project,
> without looking at mpfr or at another implementation, and it would be
> interesting to understand how it works in mpfr. Are there any documents
> or papers that describe it?

You might be heading towards interval arithmetic.  The mpfr web page
has some links on that, and some preliminary code using mpfr to do it.