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

mercurial at gmplib.org mercurial at gmplib.org
Fri Apr 13 11:13:00 CEST 2012


details:   /var/hg/gmp/rev/9b97bd92e175
changeset: 14815:9b97bd92e175
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Apr 13 10:56:47 2012 +0200
description:
mpz/bin_uiui.c: Add ASSERT.

details:   /var/hg/gmp/rev/92d03208c873
changeset: 14816:92d03208c873
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Apr 13 11:11:23 2012 +0200
description:
mini-gmp/mini-gmp.c (mpz_fac_ui, mpz_bin_uiui): moved from gen-fac_ui.c

diffstat:

 ChangeLog           |   4 ++++
 gen-fac_ui.c        |  30 ------------------------------
 mini-gmp/mini-gmp.c |  33 +++++++++++++++++++++++++++++++++
 mini-gmp/mini-gmp.h |   3 +++
 mpz/bin_uiui.c      |   2 ++
 5 files changed, 42 insertions(+), 30 deletions(-)

diffs (128 lines):

diff -r 91a170dd3928 -r 92d03208c873 ChangeLog
--- a/ChangeLog	Fri Apr 13 10:08:29 2012 +0200
+++ b/ChangeLog	Fri Apr 13 11:11:23 2012 +0200
@@ -3,6 +3,10 @@
 	* mpz/bin_uiui.c: Rewrite.
 	* gen-fac_ui.c: Generate new constants for bin_uiui.
 
+	* mini-gmp/mini-gmp.h (mpz_fac_ui, mpz_bin_uiui): New definitions.
+	* mini-gmp/mini-gmp.c (mpz_fac_ui, mpz_bin_uiui): Trivial
+	implementation.
+
 2012-04-12  Torbjorn Granlund  <tege at gmplib.org>
 
 	* mpn/x86_64/fastsse/lshift-movdqu2.asm: New file.
diff -r 91a170dd3928 -r 92d03208c873 gen-fac_ui.c
--- a/gen-fac_ui.c	Fri Apr 13 10:08:29 2012 +0200
+++ b/gen-fac_ui.c	Fri Apr 13 11:11:23 2012 +0200
@@ -22,36 +22,6 @@
 
 #include "bootstrap.c"
 
-void
-mpz_fac_ui (mpz_t x, unsigned long n)
-{
-  if (n < 2) {
-    mpz_set_ui (x, 1);
-    return;
-  }
-  mpz_set_ui (x, n);
-  for (;--n > 1;)
-    mpz_mul_ui (x, x, n);
-}
-
-void
-mpz_bin_uiui (mpz_t r, unsigned long int n, unsigned long int k)
-{
-  mpz_t t;
-
-  if (k > n) {
-    r->_mp_size = 0;
-    return;
-  }
-  mpz_fac_ui (r, n);
-  mpz_init (t);
-  mpz_fac_ui (t, k);
-  mpz_divexact (r, r, t);
-  mpz_fac_ui (t, n - k);
-  mpz_divexact (r, r, t);
-  mpz_clear (t);
-}
-
 int
 mpz_remove_twos (mpz_t x)
 {
diff -r 91a170dd3928 -r 92d03208c873 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Fri Apr 13 10:08:29 2012 +0200
+++ b/mini-gmp/mini-gmp.c	Fri Apr 13 11:11:23 2012 +0200
@@ -3206,6 +3206,39 @@
 }
 
 
+/* Combinatorics */
+
+void
+mpz_fac_ui (mpz_t x, unsigned long n)
+{
+  if (n < 2) {
+    mpz_set_ui (x, 1);
+    return;
+  }
+  mpz_set_ui (x, n);
+  for (;--n > 1;)
+    mpz_mul_ui (x, x, n);
+}
+
+void
+mpz_bin_uiui (mpz_t r, unsigned long n, unsigned long k)
+{
+  mpz_t t;
+
+  if (k > n) {
+    r->_mp_size = 0;
+    return;
+  }
+  mpz_fac_ui (r, n);
+  mpz_init (t);
+  mpz_fac_ui (t, k);
+  mpz_divexact (r, r, t);
+  mpz_fac_ui (t, n - k);
+  mpz_divexact (r, r, t);
+  mpz_clear (t);
+}
+
+
 /* Logical operations and bit manipulation. */
 
 /* Numbers are treated as if represented in two's complement (and
diff -r 91a170dd3928 -r 92d03208c873 mini-gmp/mini-gmp.h
--- a/mini-gmp/mini-gmp.h	Fri Apr 13 10:08:29 2012 +0200
+++ b/mini-gmp/mini-gmp.h	Fri Apr 13 11:11:23 2012 +0200
@@ -180,6 +180,9 @@
 void mpz_rootrem (mpz_t, mpz_t, const mpz_t, unsigned long);
 int mpz_root (mpz_t, const mpz_t, unsigned long);
 
+void mpz_fac_ui (mpz_t, unsigned long);
+void mpz_bin_uiui (mpz_t, unsigned long, unsigned long);
+
 int mpz_tstbit (const mpz_t, mp_bitcnt_t);
 void mpz_setbit (mpz_t, mp_bitcnt_t);
 void mpz_clrbit (mpz_t, mp_bitcnt_t);
diff -r 91a170dd3928 -r 92d03208c873 mpz/bin_uiui.c
--- a/mpz/bin_uiui.c	Fri Apr 13 10:08:29 2012 +0200
+++ b/mpz/bin_uiui.c	Fri Apr 13 11:11:23 2012 +0200
@@ -437,12 +437,14 @@
   SIZ(r) = rn;
 }
 
+/* WARNING: it assumes that n fits in a limb! */
 void
 mpz_bin_uiui (mpz_ptr r, unsigned long int n, unsigned long int k)
 {
   if (UNLIKELY (n < k)) {
     SIZ (r) = 0;
   } else {
+    ASSERT (n <= GMP_NUMB_MAX);
     /* Rewrite bin(n,k) as bin(n,n-k) if that is smaller. */
     k = MIN (k, n - k);
     if (k < 2) {


More information about the gmp-commit mailing list