mini-gmp mpz_{get,set}_d not fully compatible with GMP
Niels Möller
nisse at lysator.liu.se
Sun May 20 19:57:54 UTC 2018
"Marco Bodrato" <bodrato at mail.dm.unipi.it> writes:
> float.h is only used for
>
> +#if defined(DBL_MANT_DIG) && FLT_RADIX == 2
> +#define GMP_DBL_MANT_BITS DBL_MANT_DIG
> +#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
#ifndef MINI_GMP_FLOAT_SUPPORT
#define MINI_GMP_FLOAT_SUPPORT 1
#endif
#if MINI_GMP_FLOAT_SUPPORT
#include <float.h>
#endif
...
#if MINI_GMP_FLOAT_SUPPORT
#if FLT_RADIX == 2
#define GMP_DBL_MANT_BITS DBL_MANT_DIG
#else
/* 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)
#endif
I.e., use float.h constants unconditionally whenever float support is
enabled. And gmp/bootstrap.c would then #define MINI_GMP_FLOAT_SUPPORT
0.
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).
Regards,
/Niels
--
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