summaryrefslogtreecommitdiff
path: root/mpq
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2018-02-19 16:21:34 +0100
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2018-02-19 16:21:34 +0100
commitbc3e66653529ff9159780f9b89ef045a4b3f57ab (patch)
treee07767cbc9d9b90e27a0c25ef6847f3263e69fb0 /mpq
parente00d6e06c407b205d3213e3c023d2924722edbb0 (diff)
downloadgmp-bc3e66653529ff9159780f9b89ef045a4b3f57ab.tar.gz
mpq/get_d.c: compare (zeros > 0) just once, not 3 times...
Diffstat (limited to 'mpq')
-rw-r--r--mpq/get_d.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/mpq/get_d.c b/mpq/get_d.c
index 9d17ad1d5..86de3453c 100644
--- a/mpq/get_d.c
+++ b/mpq/get_d.c
@@ -104,10 +104,10 @@ mpq_get_d (mpq_srcptr src)
{
double res;
mp_srcptr np, dp;
- mp_ptr remp, tp;
+ mp_ptr remp;
mp_size_t nsize = SIZ(NUM(src));
mp_size_t dsize = SIZ(DEN(src));
- mp_size_t qsize, prospective_qsize, zeros, chop, tsize;
+ mp_size_t qsize, prospective_qsize, zeros;
mp_size_t sign_quotient = nsize;
long exp;
#define N_QLIMBS (1 + (sizeof (double) + GMP_LIMB_BYTES-1) / GMP_LIMB_BYTES)
@@ -133,34 +133,26 @@ mpq_get_d (mpq_srcptr src)
zeros = qsize - prospective_qsize; /* padding n to get qsize */
exp = (long) -zeros * GMP_NUMB_BITS; /* relative to low of qp */
- chop = MAX (-zeros, 0); /* negative zeros means shorten n */
- np += chop;
- nsize -= chop;
- zeros += chop; /* now zeros >= 0 */
-
- tsize = nsize + zeros; /* size for possible copy of n */
-
- if (WANT_TMP_DEBUG)
- {
- /* separate blocks, for malloc debugging */
- remp = TMP_ALLOC_LIMBS (dsize);
- tp = (zeros > 0 ? TMP_ALLOC_LIMBS (tsize) : NULL);
- }
- else
- {
- /* one block with conditionalized size, for efficiency */
- remp = TMP_ALLOC_LIMBS (dsize + (zeros > 0 ? tsize : 0));
- tp = remp + dsize;
- }
-
/* zero extend n into temporary space, if necessary */
if (zeros > 0)
{
+ mp_ptr tp;
+ mp_size_t tsize;
+ tsize = nsize + zeros; /* size for copy of n */
+
+ TMP_ALLOC_LIMBS_2 (remp, dsize, tp, tsize);
MPN_ZERO (tp, zeros);
MPN_COPY (tp+zeros, np, nsize);
np = tp;
nsize = tsize;
}
+ else /* negative zeros means shorten n */
+ {
+ np -= zeros;
+ nsize += zeros;
+
+ remp = TMP_ALLOC_LIMBS (dsize);
+ }
ASSERT (qsize == nsize - dsize + 1);
mpn_tdiv_qr (qp, remp, (mp_size_t) 0, np, nsize, dp, dsize);