[Gmp-commit] /var/hg/gmp: 3 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Tue Apr 10 22:34:59 CEST 2012
details: /var/hg/gmp/rev/d220a085dceb
changeset: 14801:d220a085dceb
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Apr 10 22:23:04 2012 +0200
description:
mini-gmp.h (mpz_out_str): Test also __STDIO_LOADED (for VMS).
details: /var/hg/gmp/rev/c2873ceb9d92
changeset: 14802:c2873ceb9d92
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Apr 10 22:31:37 2012 +0200
description:
mini-gmp/mini-gmp.c (mpz_root): Moved from gen-fac_ui.c.
details: /var/hg/gmp/rev/b04e4e6b6c95
changeset: 14803:b04e4e6b6c95
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Apr 10 22:32:14 2012 +0200
description:
mpz/2fac_ui.c: Cosmetic change.
diffstat:
ChangeLog | 8 ++++++++
gen-fac_ui.c | 33 ---------------------------------
mini-gmp/mini-gmp.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
mini-gmp/mini-gmp.h | 5 ++++-
mpz/2fac_ui.c | 7 +++----
5 files changed, 58 insertions(+), 39 deletions(-)
diffs (158 lines):
diff -r 469b4e6699c9 -r b04e4e6b6c95 ChangeLog
--- a/ChangeLog Mon Apr 09 20:02:37 2012 +0200
+++ b/ChangeLog Tue Apr 10 22:32:14 2012 +0200
@@ -1,3 +1,11 @@
+2012-04-10 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+ * gen-fac_ui.c (mpz_root): Remove.
+ * mini-gmp/mini-gmp.c (mpz_root): New, support negative operands.
+ * mini-gmp/mini-gmp.h (mpz_root): define.
+ (mpz_out_str): Test also __STDIO_LOADED (for VMS).
+ * mpz/2fac_ui.c: Cosmetic change.
+
2012-04-05 Torbjorn Granlund <tege at gmplib.org>
* mpn/powerpc64/p7/popcount.asm: Properly extend arg n for mode32.
diff -r 469b4e6699c9 -r b04e4e6b6c95 gen-fac_ui.c
--- a/gen-fac_ui.c Mon Apr 09 20:02:37 2012 +0200
+++ b/gen-fac_ui.c Tue Apr 10 22:32:14 2012 +0200
@@ -23,39 +23,6 @@
#include "bootstrap.c"
-/* x=floor(y^(1/z)) */
-void
-mpz_root (mpz_t x, mpz_t y, unsigned long z)
-{
- mpz_t t, u, v;
-
- if (mpz_cmp_ui (y, 1) <= 0)
- {
- mpz_set (x, y);
- return;
- }
- mpz_init (t);
- mpz_init (v);
- mpz_init_set_ui (u, 1);
- mpz_mul_2exp (u, u, mpz_sizeinbase (y, 2) / z + 1);
- do
- {
- mpz_pow_ui (t, u, z - 1);
- mpz_tdiv_q (t, y, t);
- mpz_mul_ui (v, u, z - 1);
- mpz_add (t, t, v);
- mpz_tdiv_q_ui (t, t, z);
- if (mpz_cmp (t, u) >= 0)
- break;
- mpz_set (u, t);
- }
- while (1);
- mpz_set (x, u);
- mpz_clear (u);
- mpz_clear (v);
- mpz_clear (t);
-}
-
/* returns 0 on success */
int
gen_consts (int numb, int nail, int limb)
diff -r 469b4e6699c9 -r b04e4e6b6c95 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c Mon Apr 09 20:02:37 2012 +0200
+++ b/mini-gmp/mini-gmp.c Tue Apr 10 22:32:14 2012 +0200
@@ -2938,7 +2938,7 @@
}
-/* Higher level operations (sqrt and pow) */
+/* Higher level operations (sqrt, pow and root) */
/* Compute s = floor(sqrt(u)) and r = u - s^2. Allows r == NULL */
void
@@ -3143,6 +3143,48 @@
mpz_clear (e);
}
+/* x=floor(y^(1/z)) */
+void
+mpz_root (mpz_t x, const mpz_t y, unsigned long z)
+{
+ mpz_t t, u, v, ty;
+
+ if (y->_mp_size < 0 && (z & 1) == 0)
+ gmp_die ("mpz_root: Negative argument, with even root.");
+ if (z == 0)
+ gmp_die ("mpz_root: Zeroth root.");
+
+ if (mpz_cmp_ui (y, 1) <= 0) {
+ mpz_set (x, y);
+ return;
+ }
+
+ ty->_mp_size = GMP_ABS (y->_mp_size);
+ ty->_mp_d = y->_mp_d;
+
+ mpz_init (t);
+ mpz_init (v);
+ mpz_init (u);
+ mpz_setbit (t, mpz_sizeinbase (ty, 2) / z + 1);
+
+ do {
+ mpz_set (u, t);
+ mpz_pow_ui (t, u, z - 1);
+ mpz_tdiv_q (t, ty, t);
+ mpz_mul_ui (v, u, z - 1);
+ mpz_add (t, t, v);
+ mpz_tdiv_q_ui (t, t, z);
+ } while (mpz_cmp (t, u) < 0);
+
+ if (y->_mp_size < 0)
+ mpz_neg (x, u);
+ else
+ mpz_set (x, u);
+ mpz_clear (u);
+ mpz_clear (v);
+ mpz_clear (t);
+}
+
/* Logical operations and bit manipulation. */
diff -r 469b4e6699c9 -r b04e4e6b6c95 mini-gmp/mini-gmp.h
--- a/mini-gmp/mini-gmp.h Mon Apr 09 20:02:37 2012 +0200
+++ b/mini-gmp/mini-gmp.h Tue Apr 10 22:32:14 2012 +0200
@@ -177,6 +177,8 @@
void mpz_powm (mpz_t, const mpz_t, const mpz_t, const mpz_t);
void mpz_powm_ui (mpz_t, const mpz_t, unsigned long, const mpz_t);
+void mpz_root (mpz_t, const mpz_t, 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);
@@ -230,7 +232,8 @@
|| defined (__STDIO__) /* Apple MPW MrC */ \
|| defined (_MSL_STDIO_H) /* Metrowerks */ \
|| defined (_STDIO_H_INCLUDED) /* QNX4 */ \
- || defined (_ISO_STDIO_ISO_H) /* Sun C++ */
+ || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ \
+ || defined (__STDIO_LOADED) /* VMS */
size_t mpz_out_str (FILE *, int, const mpz_t);
#endif
diff -r 469b4e6699c9 -r b04e4e6b6c95 mpz/2fac_ui.c
--- a/mpz/2fac_ui.c Mon Apr 09 20:02:37 2012 +0200
+++ b/mpz/2fac_ui.c Tue Apr 10 22:32:14 2012 +0200
@@ -55,10 +55,9 @@
if ((n & 1) == 0) { /* n is even, n = 2k, (2k)!! = k! 2^k */
mp_limb_t count;
- popc_limb (count, n);
- count = n - count;
- n >>= 1;
- mpz_oddfac_1 (x, n, 0);
+ popc_limb (count, n); /* popc(n) == popc(k) */
+ count = n - count; /* n - popc(n) == k + k - popc(k) */
+ mpz_oddfac_1 (x, n >> 1, 0);
mpz_mul_2exp (x, x, count);
} else { /* n is odd */
static const mp_limb_t tabled[] = { ONE_LIMB_ODD_DOUBLEFACTORIAL_TABLE };
More information about the gmp-commit
mailing list