[Gmp-commit] /var/hg/gmp: mpq/get_d.c: Replace tdiv_qr with div_q.

mercurial at gmplib.org mercurial at gmplib.org
Tue Feb 20 18:12:17 UTC 2018


details:   /var/hg/gmp/rev/a7944ea105aa
changeset: 17566:a7944ea105aa
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Feb 20 19:12:02 2018 +0100
description:
mpq/get_d.c: Replace tdiv_qr with div_q.

diffstat:

 ChangeLog   |   2 +-
 mpq/get_d.c |  27 +++++++++++++--------------
 2 files changed, 14 insertions(+), 15 deletions(-)

diffs (82 lines):

diff -r 7d8cf5cb5203 -r a7944ea105aa ChangeLog
--- a/ChangeLog	Mon Feb 19 16:21:34 2018 +0100
+++ b/ChangeLog	Tue Feb 20 19:12:02 2018 +0100
@@ -3,7 +3,7 @@
 	* tune/Makefile.am: Disallow parallel make (thanks Vincent Lefevre).
 	* mpq/swap.c: Use *_SWAP_* macros.
 	* mpq/cmp_ui.c: One more little shortcut, comparing fractions to 1.
-	* mpq/get_d.c: compare (zeros > 0) just once.
+	* mpq/get_d.c: Compare (zeros > 0) once, replace tdiv_qr with div_q.
 
 2018-02-09  Torbjörn Granlund  <tg at gmplib.org>
 
diff -r 7d8cf5cb5203 -r a7944ea105aa mpq/get_d.c
--- a/mpq/get_d.c	Mon Feb 19 16:21:34 2018 +0100
+++ b/mpq/get_d.c	Tue Feb 20 19:12:02 2018 +0100
@@ -1,6 +1,6 @@
 /* double mpq_get_d (mpq_t src) -- mpq to double, rounding towards zero.
 
-Copyright 1995, 1996, 2001-2005 Free Software Foundation, Inc.
+Copyright 1995, 1996, 2001-2005, 2018 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -104,7 +104,7 @@
 {
   double res;
   mp_srcptr np, dp;
-  mp_ptr remp;
+  mp_ptr temp;
   mp_size_t nsize = SIZ(NUM(src));
   mp_size_t dsize = SIZ(DEN(src));
   mp_size_t qsize, prospective_qsize, zeros;
@@ -127,8 +127,8 @@
   np = PTR(NUM(src));
   dp = PTR(DEN(src));
 
-  prospective_qsize = nsize - dsize + 1;   /* from using given n,d */
-  qsize = N_QLIMBS + 1;                    /* desired qsize */
+  prospective_qsize = nsize - dsize;       /* from using given n,d */
+  qsize = N_QLIMBS;                        /* desired qsize */
 
   zeros = qsize - prospective_qsize;       /* padding n to get qsize */
   exp = (long) -zeros * GMP_NUMB_BITS;     /* relative to low of qp */
@@ -136,14 +136,13 @@
   /* 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 */
+      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;
+      temp = TMP_ALLOC_LIMBS (tsize + 1);
+      MPN_FILL (temp, zeros, 0);
+      MPN_COPY (temp + zeros, np, nsize);
+      np = temp;
       nsize = tsize;
     }
   else /* negative zeros means shorten n */
@@ -151,14 +150,14 @@
       np -= zeros;
       nsize += zeros;
 
-      remp = TMP_ALLOC_LIMBS (dsize);
+      temp = TMP_ALLOC_LIMBS (nsize + 1);
     }
 
-  ASSERT (qsize == nsize - dsize + 1);
-  mpn_tdiv_qr (qp, remp, (mp_size_t) 0, np, nsize, dp, dsize);
+  ASSERT (qsize == nsize - dsize);
+  mpn_div_q (qp, np, nsize, dp, dsize, temp);
 
   /* strip possible zero high limb */
-  qsize -= (qp[qsize-1] == 0);
+  qsize += (qp[qsize] != 0);
 
   res = mpn_get_d (qp, qsize, sign_quotient, exp);
   TMP_FREE;


More information about the gmp-commit mailing list