MPF fits in 64bit double?

Julien D Arques acc.gccquestions at gmail.com
Fri Apr 28 09:49:18 CEST 2023


Thanks Paul, I will do that.
@Richard thank you as well

Bests

On Fri, 28 Apr 2023 at 07:40, Paul Zimmermann <Paul.Zimmermann at inria.fr>
wrote:

> > 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