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

mercurial at gmplib.org mercurial at gmplib.org
Thu Aug 14 06:55:48 UTC 2014


details:   /var/hg/gmp/rev/b93f4adecc21
changeset: 16470:b93f4adecc21
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Aug 14 08:54:24 2014 +0200
description:
mpq/canonicalize.c: Earlier check for negative denominator.

details:   /var/hg/gmp/rev/d3eaeb7dbed2
changeset: 16471:d3eaeb7dbed2
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Aug 14 08:54:41 2014 +0200
description:
mpq/set_d.c: Stricter allocation.

details:   /var/hg/gmp/rev/ba37136979dc
changeset: 16472:ba37136979dc
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Aug 14 08:55:38 2014 +0200
description:
ChangeLog

diffstat:

 ChangeLog          |   5 +++++
 mpq/canonicalize.c |  17 ++++++++---------
 mpq/set_d.c        |  21 ++++++++++-----------
 3 files changed, 23 insertions(+), 20 deletions(-)

diffs (131 lines):

diff -r 0014cbb7a4d8 -r ba37136979dc ChangeLog
--- a/ChangeLog	Sun Aug 03 00:47:32 2014 +0200
+++ b/ChangeLog	Thu Aug 14 08:55:38 2014 +0200
@@ -1,3 +1,8 @@
+2014-08-14 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpq/canonicalize.c: Earlier check for negative denominator.
+	* mpq/set_d.c: Stricter allocation.
+
 2014-08-03  Torbjörn Granlund  <tege at gmplib.org>
 
 	* mpn/x86_64/bobcat/mul_1.asm: Fix typo in offset affecting DOS64.
diff -r 0014cbb7a4d8 -r ba37136979dc mpq/canonicalize.c
--- a/mpq/canonicalize.c	Sun Aug 03 00:47:32 2014 +0200
+++ b/mpq/canonicalize.c	Thu Aug 14 08:55:38 2014 +0200
@@ -1,7 +1,7 @@
 /* mpq_canonicalize(op) -- Remove common factors of the denominator and
    numerator in OP.
 
-Copyright 1991, 1994-1996, 2000, 2001, 2005 Free Software Foundation, Inc.
+Copyright 1991, 1994-1996, 2000, 2001, 2005, 2014 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -38,14 +38,19 @@
   mpz_t gcd;
   TMP_DECL;
 
-  if (UNLIKELY (SIZ(DEN(op)) == 0))
+  if (SIZ(DEN(op)) < 0)
+    {
+      SIZ(NUM(op)) = -SIZ(NUM(op));
+      SIZ(DEN(op)) = -SIZ(DEN(op));
+    }
+  else if (UNLIKELY (SIZ(DEN(op)) == 0))
     DIVIDE_BY_ZERO;
 
   TMP_MARK;
 
   /* ??? Dunno if the 1+ is needed.  */
   MPZ_TMP_INIT (gcd, 1 + MAX (ABSIZ(NUM(op)),
-			      ABSIZ(DEN(op))));
+			      SIZ(DEN(op))));
 
   mpz_gcd (gcd, NUM(op), DEN(op));
   if (! MPZ_EQUAL_1_P (gcd))
@@ -53,11 +58,5 @@
       mpz_divexact_gcd (NUM(op), NUM(op), gcd);
       mpz_divexact_gcd (DEN(op), DEN(op), gcd);
     }
-
-  if (SIZ(DEN(op)) < 0)
-    {
-      SIZ(NUM(op)) = -SIZ(NUM(op));
-      SIZ(DEN(op)) = -SIZ(DEN(op));
-    }
   TMP_FREE;
 }
diff -r 0014cbb7a4d8 -r ba37136979dc mpq/set_d.c
--- a/mpq/set_d.c	Sun Aug 03 00:47:32 2014 +0200
+++ b/mpq/set_d.c	Thu Aug 14 08:55:38 2014 +0200
@@ -1,6 +1,6 @@
 /* mpq_set_d(mpq_t q, double d) -- Set q to d without rounding.
 
-Copyright 2000, 2002, 2003, 2012 Free Software Foundation, Inc.
+Copyright 2000, 2002, 2003, 2012, 2014 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -81,9 +81,8 @@
 	  return;
 	}
 
-      dn = -exp;
-      np = MPZ_NEWALLOC (NUM(dest), 3);
 #if LIMBS_PER_DOUBLE == 4
+      np = MPZ_NEWALLOC (NUM(dest), 4);
       if ((tp[0] | tp[1] | tp[2]) == 0)
 	np[0] = tp[3], nn = 1;
       else if ((tp[0] | tp[1]) == 0)
@@ -94,6 +93,7 @@
 	np[3] = tp[3], np[2] = tp[2], np[1] = tp[1], np[0] = tp[0], nn = 4;
 #endif
 #if LIMBS_PER_DOUBLE == 3
+      np = MPZ_NEWALLOC (NUM(dest), 3);
       if ((tp[0] | tp[1]) == 0)
 	np[0] = tp[2], nn = 1;
       else if (tp[0] == 0)
@@ -102,13 +102,14 @@
 	np[2] = tp[2], np[1] = tp[1], np[0] = tp[0], nn = 3;
 #endif
 #if LIMBS_PER_DOUBLE == 2
+      np = MPZ_NEWALLOC (NUM(dest), 2);
       if (tp[0] == 0)
 	np[0] = tp[1], nn = 1;
       else
 	np[1] = tp[1], np[0] = tp[0], nn = 2;
 #endif
-      dn += nn + 1;
-      ASSERT_ALWAYS (dn > 0);
+      dn = nn + 1 - exp;
+      ASSERT (dn > 0); /* -exp >= -1; nn >= 1*/
       dp = MPZ_NEWALLOC (DEN(dest), dn);
       MPN_ZERO (dp, dn - 1);
       dp[dn - 1] = 1;
@@ -117,11 +118,10 @@
 	{
 	  mpn_rshift (np, np, nn, c);
 	  nn -= np[nn - 1] == 0;
-	  mpn_rshift (dp, dp, dn, c);
-	  dn -= dp[dn - 1] == 0;
+	  --dn;
+	  dp[dn - 1] = CNST_LIMB(1) << (GMP_LIMB_BITS - c);
 	}
       SIZ(DEN(dest)) = dn;
-      SIZ(NUM(dest)) = negative ? -nn : nn;
     }
   else
     {
@@ -158,9 +158,8 @@
 	  break;
 #endif
 	}
-      dp = PTR(DEN(dest));
-      dp[0] = 1;
+      *PTR(DEN(dest)) = 1;
       SIZ(DEN(dest)) = 1;
-      SIZ(NUM(dest)) = negative ? -nn : nn;
     }
+  SIZ(NUM(dest)) = negative ? -nn : nn;
 }


More information about the gmp-commit mailing list