mpz_get_d precision
Kevin Ryde
user42 at zip.com.au
Fri Apr 30 23:11:52 CEST 2004
Sylvain Pion <Sylvain.Pion at sophia.inria.fr> writes:
>
> 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.
The present rounding is unspecified, and is imperfect in fact.
> void mpz_get_interval(mpz_t z, double *lower, double *upper);
> void mpq_get_interval(mpq_t z, double *lower, double *upper);
Hmm. I'm not sure about that, I'd worry about getting too clever
about hardware floats.
> 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've recently made a revision to clean up the rounding, making all the
get_d functions truncate the mantissa towards zero. (Because it's
efficient and easy, and it matches other conversions like mpz_set_f.)
Perhaps with that guaranteed you can get the effect you're after.
get_d gives the lower value, and if it's not exactly equal to the
input then nextafter() gives the upper. (Vice versa for negatives.)
> 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.
Thanks, I'll clarify that. (The returned value and exponent are both
zero.)
More information about the gmp-devel
mailing list