mini-gmp mpz_{get,set}_d not fully compatible with GMP

Niels Möller nisse at
Sun May 20 19:57:54 UTC 2018

"Marco Bodrato" <bodrato at> writes:

> float.h is only used for
> +#if defined(DBL_MANT_DIG) && FLT_RADIX == 2
> +#else
> +#define GMP_DBL_MANT_BITS (53)
> +#endif
> This constant is used only by the new version of get_d, to convert the
> correct number of bits and avoid rounding.
> I mean, the functions do not "depend on" float.h , and we don't need to
> exclude them. Maybe we should decide for a different default value...

You could consider making this into small step towards modularizing
mini-gmp. Something like


#include <float.h>


#if FLT_RADIX == 2
/* What are our options?

   Fail as unsupported? Display warning? Or document expected breakage
   on systems for non-binary floats? Or approximate as DBL_MANT_DIG *
   log2(FLT_RADIX) ? */
#define GMP_DBL_MANT_BITS (53)

I.e., use float.h constants unconditionally whenever float support is
enabled. And gmp/bootstrap.c would then #define MINI_GMP_FLOAT_SUPPORT

Independent of this suggestion, I have two minor comments on the your
change (43659273c9cf): I think the DONT_USE_FLOAT_H macro should have a
GMP or MINI_GMP prefix. And it would be nice with a test, e.g, based on
your sample program converting integers 2^i +/- 1 to double and
comparing the results (before your fix, mini-gmp rounded to nearest,
producing identical doubles for large enough i).


Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.

More information about the gmp-devel mailing list