diff options
author | Kevin Ryde <user42@zip.com.au> | 2001-06-15 00:35:11 +0200 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2001-06-15 00:35:11 +0200 |
commit | f607fadf9c5c4be370faaf197392d5f994db88a0 (patch) | |
tree | e61e03a92d2e87abb2c68b88ea8e103da127336c /mpz | |
parent | dc09070938e439163ad5b739a5aa009a6e358180 (diff) | |
download | gmp-f607fadf9c5c4be370faaf197392d5f994db88a0.tar.gz |
* mpz/set_f.c: Share MPN_COPY between pad and trunc cases, do exp<=0
test earlier, store SIZ(w) earlier.
Diffstat (limited to 'mpz')
-rw-r--r-- | mpz/set_f.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/mpz/set_f.c b/mpz/set_f.c index 9d48820df..6a936cdc7 100644 --- a/mpz/set_f.c +++ b/mpz/set_f.c @@ -22,37 +22,43 @@ MA 02111-1307, USA. */ #include "gmp.h" #include "gmp-impl.h" + void mpz_set_f (mpz_ptr w, mpf_srcptr u) { - mp_ptr wp, up; - mp_size_t usize, size; - mp_exp_t exp; + mp_ptr wp, up; + mp_size_t size; + mp_exp_t exp; - usize = SIZ (u); - size = ABS (usize); + /* abs(u)<1 truncates to zero */ exp = EXP (u); - - if (w->_mp_alloc < exp) - _mpz_realloc (w, exp); - - wp = w->_mp_d; - up = u->_mp_d; - if (exp <= 0) { - SIZ (w) = 0; + SIZ(w) = 0; return; } - if (exp < size) + + MPZ_REALLOC (w, exp); + wp = PTR(w); + up = PTR(u); + + size = SIZ (u); + SIZ(w) = (size >= 0 ? exp : -exp); + size = ABS (size); + + if (exp > size) { - MPN_COPY (wp, up + size - exp, exp); + /* pad with low zeros to get a total "exp" many limbs */ + mp_size_t zeros = exp - size; + MPN_ZERO (wp, zeros); + wp += zeros; } else { - MPN_ZERO (wp, exp - size); - MPN_COPY (wp + exp - size, up, size); + /* exp<=size, trucate to the high "exp" many limbs */ + up += (size - exp); + size = exp; } - w->_mp_size = usize >= 0 ? exp : -exp; + MPN_COPY (wp, up, size); } |