[Gmp-commit] /var/hg/gmp: 5 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Wed Jan 23 22:30:38 CET 2013


details:   /var/hg/gmp/rev/16d1a5be9a91
changeset: 15347:16d1a5be9a91
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Jan 23 22:07:47 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_set_str): Behaviour more adherent to the real GMP.

details:   /var/hg/gmp/rev/9dadd9803ba3
changeset: 15348:9dadd9803ba3
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Jan 23 22:08:18 2013 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/01041888932f
changeset: 15349:01041888932f
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Jan 23 22:13:05 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_cmpabs_d, mpz_cmp_d): Simplify.

details:   /var/hg/gmp/rev/77e29fbf2678
changeset: 15350:77e29fbf2678
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Jan 23 22:13:23 2013 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/829243243448
changeset: 15351:829243243448
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Jan 23 22:29:35 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_cmpabs_d): Reindent, and move ABS inside the if.

diffstat:

 ChangeLog           |   5 +++
 mini-gmp/mini-gmp.c |  84 +++++++++++++++++++---------------------------------
 2 files changed, 36 insertions(+), 53 deletions(-)

diffs (129 lines):

diff -r 716dcbb2289c -r 829243243448 ChangeLog
--- a/ChangeLog	Tue Jan 22 23:27:08 2013 +0100
+++ b/ChangeLog	Wed Jan 23 22:29:35 2013 +0100
@@ -1,3 +1,8 @@
+2013-01-23 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mini-gmp/mini-gmp.c (mpz_cmpabs_d, mpz_cmp_d): Simplify.
+	(mpz_set_str): Behaviour more adherent to the real GMP. 
+
 2013-01-22  Torbjorn Granlund  <tege at gmplib.org>
 
 	* Makefile.am (LIBGMP_LT_*, LIBGMPXX_LT_*): Bump version info.
diff -r 716dcbb2289c -r 829243243448 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Tue Jan 22 23:27:08 2013 +0100
+++ b/mini-gmp/mini-gmp.c	Wed Jan 23 22:29:35 2013 +0100
@@ -1551,63 +1551,44 @@
   double B, Bi;
   mp_size_t i;
 
-  xn = GMP_ABS (x->_mp_size);
+  xn = x->_mp_size;
   d = GMP_ABS (d);
 
-  if (xn == 0)
-    return - (d > 0.0);
-  if (d < 1.0)
-    return 1;
-
-  B = 2.0 * (double) GMP_LIMB_HIGHBIT;
-  Bi = 1.0 / B;
-
-  /* Scale d so it can be compared with the top limb. */
-  for (i = 1; i < xn; i++)
+  if (xn != 0)
     {
-      d *= Bi;
-      if (d < 1.0)
-	return 1;
+      xn = GMP_ABS (xn);
+
+      B = 2.0 * (double) GMP_LIMB_HIGHBIT;
+      Bi = 1.0 / B;
+
+      /* Scale d so it can be compared with the top limb. */
+      for (i = 1; i < xn; i++)
+	d *= Bi;
+
+      if (d >= B)
+	return -1;
+
+      /* Compare floor(d) to top limb, subtract and cancel when equal. */
+      for (i = xn; i-- > 0;)
+	{
+	  mp_limb_t f, xl;
+
+	  f = (mp_limb_t) d;
+	  xl = x->_mp_d[i];
+	  if (xl > f)
+	    return 1;
+	  else if (xl < f)
+	    return -1;
+	  d = B * (d - f);
+	}
     }
-  if (d >= B)
-    return -1;
-
-  /* Compare floor(d) to top limb, subtract and cancel when equal. */
-  for (i = xn; i-- > 0;)
-    {
-      mp_limb_t f, xl;
-
-      f = (mp_limb_t) d;
-      xl = x->_mp_d[i];
-      if (xl > f)
-	return 1;
-      else if (xl < f)
-	return -1;
-      d = B * (d - f);
-    }
-
-  if (d > 0)
-    return -1;
-  else
-    return 0;
+  return - (d > 0.0);
 }
 
 int
 mpz_cmp_d (const mpz_t x, double d)
 {
-  mp_size_t xn = x->_mp_size;
-
-  if (xn == 0)
-    {
-      if (d < 0.0)
-	return 1;
-      else if (d > 0.0)
-	return -1;
-      else
-	return 0;
-    }
-
-  if (xn < 0)
+  if (x->_mp_size < 0)
     {
       if (d >= 0.0)
 	return -1;
@@ -1616,7 +1597,7 @@
     }
   else
     {
-      if (d <= 0.0)
+      if (d < 0.0)
 	return 1;
       else
 	return mpz_cmpabs_d (x, d);
@@ -3883,10 +3864,7 @@
   if (*sp == '-')
     {
       sign = 1;
-
-      do
-	sp++;
-      while (isspace( (unsigned char) *sp));
+      sp++;
     }
   else
     sign = 0;


More information about the gmp-commit mailing list