Questions.. Questions ..

Lucien Hayen l.hayen at tiscali.be
Wed Nov 23 13:34:41 CET 2005


Sir,

In an effort to understand exactly what the internals of mpf_t mean,
(writing routines to enter single precision floats, long doubles,
and signed and unsigned long long integers into mpf_t items) I came
across some problems.

1) I have version 4.1.4 but the macros __GMPF_BITS_TO_PREC and
   __GMPF_PREC_TO_BITS do not seem to exist.

2) The expression sizeof(mp_limb_t) popped up so many times that
   inclusion of the exact numerical value (4 on my system) in gmp.h
   (as it is generated for each particular system) seems to be
   reasonable : #define GMP_LIMB_BYTES 4 (or whatever is the case).

3) The mpz_t structure element _mp_prec seems to have two 
   different and contradictory uses : at init time the number of
   limbs to use as precision, and the number of limbs allocated (-1).
   Later on this last meaning may be lost.
   Would it not be better to insert a _mp_alloc (or more clearly)
   a _mp_prec_max item in the mpf_t structure ? No more problems
   at clear time, no more mpf_set_prec_raw() accidents if the maximum
   precision is silently or otherwise enforced (warning on page 47 of
   the manual).

4) Clearing in general does deallocate memory, but keeps a pointer
   to now non existing memory, or worse yet, to memory allocated
   after the clear operation for purposes that need not even be
   related to GMP uses. Why not setting _mp_d to NULL so that any
   accidental second clear operation will fail there and then. Now
   it can happen somewhere later, deeper in the software, and
   possibly difficult to find.

I hope that you do not see my questions as criticism on your very
fine work and the resulting software.

Yours truly


Lucien Haijen



More information about the gmp-discuss mailing list