[Gmp-commit] /var/hg/gmp: mini-gmp/: remove some sizeof(mp_limb_t)

mercurial at gmplib.org mercurial at gmplib.org
Thu Dec 5 06:58:56 UTC 2019


details:   /var/hg/gmp/rev/2109bbf292bd
changeset: 17988:2109bbf292bd
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Dec 05 07:44:46 2019 +0100
description:
mini-gmp/: remove some sizeof(mp_limb_t)

diffstat:

 mini-gmp/mini-gmp.c |   2 +-
 mini-gmp/mini-mpq.c |  25 ++++++++++++++++---------
 2 files changed, 17 insertions(+), 10 deletions(-)

diffs (56 lines):

diff -r 79fa1e2e51b9 -r 2109bbf292bd mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Wed Dec 04 06:36:45 2019 +0100
+++ b/mini-gmp/mini-gmp.c	Thu Dec 05 07:44:46 2019 +0100
@@ -4499,7 +4499,7 @@
       limb = u->_mp_d[un-1];
       assert (limb != 0);
 
-      k = (sizeof (mp_limb_t) == 1); 
+      k = (GMP_LIMB_BITS <= CHAR_BIT);
       if (!k)
 	{
 	  do {
diff -r 79fa1e2e51b9 -r 2109bbf292bd mini-gmp/mini-mpq.c
--- a/mini-gmp/mini-mpq.c	Wed Dec 04 06:36:45 2019 +0100
+++ b/mini-gmp/mini-mpq.c	Thu Dec 05 07:44:46 2019 +0100
@@ -253,9 +253,10 @@
 {
   mpq_t t;
   assert (d != 0);
-  if (sizeof (unsigned long) == sizeof (mp_limb_t))
-    return mpq_cmp (q, mpq_roinit_normal_nn (t, (mp_srcptr) &n, n != 0, (mp_srcptr) &d, 1));
-  else {
+  if (ULONG_MAX <= GMP_LIMB_MAX) {
+    mp_limb_t nl = n, dl = d;
+    return mpq_cmp (q, mpq_roinit_normal_nn (t, &nl, n != 0, &dl, 1));
+  } else {
     int ret;
 
     mpq_init (t);
@@ -277,14 +278,20 @@
   else
     {
       mpq_t t;
-      unsigned long l_n = GMP_NEG_CAST (unsigned long, n);
 
-      if (sizeof (unsigned long) == sizeof (mp_limb_t))
-	return mpq_cmp (q, mpq_roinit_normal_nn (t, (mp_srcptr) &l_n, -1, (mp_srcptr) &d, 1));
+      if (ULONG_MAX <= GMP_LIMB_MAX)
+	{
+	  mp_limb_t nl = GMP_NEG_CAST (unsigned long, n), dl = d;
+	  return mpq_cmp (q, mpq_roinit_normal_nn (t, &nl, -1, &dl, 1));
+	}
+      else
+	{
+	  unsigned long l_n = GMP_NEG_CAST (unsigned long, n);
 
-      mpq_roinit_normal_nn (t, mpq_numref (q)->_mp_d, - mpq_numref (q)->_mp_size,
-		       mpq_denref (q)->_mp_d, mpq_denref (q)->_mp_size);
-      return - mpq_cmp_ui (t, l_n, d);
+	  mpq_roinit_normal_nn (t, mpq_numref (q)->_mp_d, - mpq_numref (q)->_mp_size,
+				mpq_denref (q)->_mp_d, mpq_denref (q)->_mp_size);
+	  return - mpq_cmp_ui (t, l_n, d);
+	}
     }
 }
 


More information about the gmp-commit mailing list