mpz_get_d precision

Sylvain Pion Sylvain.Pion at sophia.inria.fr
Fri Apr 30 15:50:04 CEST 2004


Dear GMP developpers,

I have a request about the mp[zq]_get_d functions, which convert mpz/mpq to
double.

I use these functions in order to convert mpz/mpq to intervals which bounds
are double.  Then I use interval arithmetic to play with these intervals.

The critical aspect here is that I need to be certain that the interval
(which can be infinite) contains the exact value.

The mp[zq]_get_d and mpz_get_d_2exp functions do not provide enough
precision guarantees for me to do so.  At least this is not documented.


I would like to know if someone is taking care of this issue in GMP, or
if I should do it myself, and if such a change would be welcome in GMP,
and if so, under which form exactly.

The interface I could propose is something like :

void mpz_get_interval(mpz_t z, double *lower, double *upper);
void mpq_get_interval(mpq_t z, double *lower, double *upper);

With the semantics described above.
Variants returning an exponent like mpz_get_d_2exp would also be possible.

Of course, there are other possibilities, such as documenting that the result
of mp[zq]_get_d are the closest double values from the exact values
(i.e. rounding to nearest).

I would personnaly prefer the versions with intervals, which can have a width
larger than one ulp, which makes it probably easier/faster to implement.

I am also interested in having this available in the C++ interface.


Another minor remark : the documentation of mpz_get_d_2exp  does not describe
what happens if the input is zero : the condition 0.5<=abs(d)<1 does not allow
d to be zero.

-- 
Sylvain


More information about the gmp-devel mailing list