mpf_clear vs altered precision

Sisyphus sisyphus1 at optusnet.com.au
Wed Dec 21 03:37:45 CET 2005


----- Original Message ----- 
From: "Jim White" <mathimagics at yahoo.co.uk>
To: <gmp-discuss at swox.com>
Sent: Wednesday, December 21, 2005 12:52 PM
Subject: mpf_clear vs altered precision


>
> If I initialise an mpf item, and during a computation
> I reduce its precision directly (by reducing the
> mp_prec member), do I need to restore the original
> mp_prec value before I clear it with mpf_clear?
>
> Or does GMP itself keep track of the number of limbs
> originally allocated?
>

I think it depends upon which function you use to reduce the precision.
Looks to me that, if you use mpf_set_prec(), allocated memory is being
tracked. The docs say that the mpf_set_prec() function requires a call to
realloc() - which I take to imply that there's no need to "restore" before
you "clear".
Things are a little trickier if you call mpf_set_prec_raw(), which doesn't
change the allocated memory. Make sure you read its documentation if you
intend to use it.

Cheers,
Rob



More information about the gmp-discuss mailing list