[Gmp-commit] /var/hg/gmp: Correct last change.

mercurial at gmplib.org mercurial at gmplib.org
Sat Mar 19 19:39:05 CET 2011


details:   /var/hg/gmp/rev/2a9f1b958fd9
changeset: 14070:2a9f1b958fd9
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Sat Mar 19 19:38:58 2011 +0100
description:
Correct last change.

diffstat:

 mpz/fac_ui.c |  12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diffs (35 lines):

diff -r cce6c818dea7 -r 2a9f1b958fd9 mpz/fac_ui.c
--- a/mpz/fac_ui.c	Sat Mar 19 17:20:59 2011 +0100
+++ b/mpz/fac_ui.c	Sat Mar 19 19:38:58 2011 +0100
@@ -145,14 +145,18 @@
 
   if (n <= ((unsigned long) 1) << (APCONST))
     {
-      MPZ_REALLOC (x, 4 * z);
+      /* This strange allocation was deduced from an earlier, poorly documented
+	 expression that used mpz_realloc2.  FIXME.  */
+      MPZ_REALLOC (x, z / (GMP_NUMB_BITS / 4) + 1);
       ap_product_small (x, CNST_LIMB(2), CNST_LIMB(1), n - 1, 4L);
       return;
     }
   if (n <= ((unsigned long) 1) << (APCONST + 1))
     {				/*  use n!=odd(1,n)*(n/2)!*2^(n/2)         */
       mpz_init2 (t1, 2 * z);
-      MPZ_REALLOC (x, 4 * z);
+      /* This strange allocation was deduced from an earlier, poorly documented
+	 expression that used mpz_realloc2.  FIXME.  */
+      MPZ_REALLOC (x, z / (GMP_NUMB_BITS / 4) + 1);
       ap_product_small (x, CNST_LIMB(2), CNST_LIMB(1), n / 2 - 1, 4L);
       ap_product_small (t1, CNST_LIMB(3), CNST_LIMB(2), (n - 1) / 2, 4L);
       mpz_mul (x, x, t1);
@@ -165,7 +169,9 @@
       /* use n!=C_2(1,n/2)^2*C_2(n/2,n)*(n/4)!*2^(n/2+n/4) all int divs
 	 so need (BITS_IN_N-APCONST+1)=(APCONST+3-APCONST+1)=4 stack entries */
       mpz_init2 (t1, 2 * z);
-      MPZ_REALLOC (x, 4 * z);
+      /* This strange allocation was deduced from an earlier, poorly documented
+	 expression that used mpz_realloc2.  FIXME.  */
+      MPZ_REALLOC (x, z / (GMP_NUMB_BITS / 4) + 1);
       for (i = 0; i < 4; i++)
 	{
 	  mpz_init2 (st[i], z);


More information about the gmp-commit mailing list