MPF fits in 64bit double?

Paul Zimmermann Paul.Zimmermann at inria.fr
Fri Apr 28 07:40:58 CEST 2023


> In my algorithm, I need to repeat some calculations up to the point the mpf
> result fits in a double (8bytes on x86_64) without loss.
> 
> I plan to use the mpf_fits_ulong_p function because it is 8 bytes as well,
> even if not a double.
> It would warrant that 64bits (and no more) are in use to store the current
> result.

mpf_fits_ulong_p will answer false for the number 2^1023, although it fits in a
double.

It will answer true for 2^64-1 (on a 64-bit platform) which does not fit in a
double.

If you can use MPFR instead of MPF, then you can do the following:

int fits_double (mpfr_t f)
{
   return mpfr_cmp_d (f, mpfr_get_d (f, MPFR_RNDN)) == 0;	
}

Best regards,
Paul Zimmermann


More information about the gmp-discuss mailing list