diff options
author | Kevin Ryde <user42@zip.com.au> | 2001-04-21 23:52:49 +0200 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2001-04-21 23:52:49 +0200 |
commit | 0eb78e777ec75b7b5c705d94af8681996fa256e5 (patch) | |
tree | b41752fc6149761a5b0eb52aa68387405956ed0c /mpf/set_prc.c | |
parent | 185b0c08284973bd2ed362ec685762ce68327665 (diff) | |
download | gmp-0eb78e777ec75b7b5c705d94af8681996fa256e5.tar.gz |
* mpf/set_prc.c: Avoid a realloc call if already the right precision.
* gmp-impl.h (MPF_BITS_TO_PREC, MPF_PREC_TO_BITS): New macros.
* mpf/get_prc.c, init2.c, set_dfl_prec.c, set_prc.c, set_prc_raw.c:
Use them.
Diffstat (limited to 'mpf/set_prc.c')
-rw-r--r-- | mpf/set_prc.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/mpf/set_prc.c b/mpf/set_prc.c index 2064fe714..32ed07f8d 100644 --- a/mpf/set_prc.c +++ b/mpf/set_prc.c @@ -26,12 +26,18 @@ void mpf_set_prec (mpf_ptr x, unsigned long int prec_in_bits) { mp_size_t prec; - mp_size_t size = ABS (x->_mp_size); + mp_size_t size; - prec = (MAX (53, prec_in_bits) + 2 * BITS_PER_MP_LIMB - 1)/BITS_PER_MP_LIMB; + /* Do nothing if we're already the right precision. This can arise if an + application is gradually increasing or decreasing its requested minimum + precision. */ + prec = MPF_PREC_TO_BITS (prec_in_bits); + if (prec == PREC(x)) + return; /* We want the most significant limbs, so move the limbs down if we are about to truncate the value. */ + size = ABS (x->_mp_size); if (size > prec + 1) { mp_size_t offset = size - (prec + 1); |