[Gmp-commit] /var/hg/gmp: mpz/bin_ui.c: Do not use ROINIT, use init()

mercurial at gmplib.org mercurial at gmplib.org
Sat Dec 30 14:48:49 UTC 2017


details:   /var/hg/gmp/rev/8df00acd12ca
changeset: 17517:8df00acd12ca
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Dec 30 15:48:40 2017 +0100
description:
mpz/bin_ui.c: Do not use ROINIT, use init()

diffstat:

 mpz/bin_ui.c |  16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diffs (60 lines):

diff -r 570604eb878d -r 8df00acd12ca mpz/bin_ui.c
--- a/mpz/bin_ui.c	Sat Dec 30 14:25:20 2017 +0100
+++ b/mpz/bin_ui.c	Sat Dec 30 15:48:40 2017 +0100
@@ -99,8 +99,8 @@
 }
 
 /* Computes (n+1)(n+2)...(n+k)/2^(k/2) using the helper function
-   rek_raising_fac, and exploiting an idea inspired by piece of code
-   that Fredrik Johansson wrote.
+   rek_raising_fac, and exploiting an idea inspired by a piece of
+   code that Fredrik Johansson wrote.
 
    Force an even k = 2i then compute:
      p  = (n+1)(n+2i)/2
@@ -150,13 +150,14 @@
 void
 mpz_bin_ui (mpz_ptr r, mpz_srcptr n, unsigned long int k)
 {
+  mpz_t      ni;
   mp_limb_t  i;
-  mpz_t      ni = MPZ_ROINIT_N (&i, 0);
   mp_size_t  negate;
 
   if (SIZ (n) < 0)
     {
       /* bin(n,k) = (-1)^k * bin(-n+k-1,k), and set ni = -n+k-1 - k = -n-1 */
+      mpz_init (ni);
       mpz_add_ui (ni, n, 1L);
       mpz_neg (ni, ni);
       negate = (k & 1);   /* (-1)^k */
@@ -172,6 +173,7 @@
 	}
 
       /* set ni = n-k */
+      mpz_init (ni);
       mpz_sub_ui (ni, n, k);
       negate = 0;
     }
@@ -214,7 +216,7 @@
 	  mpz_sub_ui (r, r, 1); /* (n+1)^2-1 */
 	  if (k == 3)
 	    {
-	      mpz_mul (r, r, ni); /* ((n+1)^2-1)(n-1) = n(n+1)(n+2) */
+	      mpz_mul (r, r, ni); /* ((n+1)^2-1)(n+1) = n(n+1)(n+2) */
 	      /* mpz_divexact_ui (r, r, 6); /\* 6=3<<1; div_by3 ? *\/ */
 	      mpn_pi1_bdiv_q_1 (PTR(r), PTR(r), SIZ(r), 3, GMP_NUMB_MASK/3*2+1, 1);
 	      MPN_NORMALIZE_NOT_ZERO (PTR(r), SIZ(r));
@@ -244,8 +246,10 @@
   else
     {
       mp_limb_t count;
-      mpz_t num = MPZ_ROINIT_N (&i, 0);
-      mpz_t den = MPZ_ROINIT_N (&i, 0);
+      mpz_t num, den;
+
+      mpz_init (num);
+      mpz_init (den);
 
       mpz_raising_fac (num, ni, k, den, r);
       popc_limb (count, k);


More information about the gmp-commit mailing list