[Gmp-commit] /var/hg/gmp-proj/mini-gmp: 2 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Wed Jan 11 22:50:12 CET 2012
details: /var/hg/gmp-proj/mini-gmp/rev/0720ed1d32e0
changeset: 61:0720ed1d32e0
user: Niels M?ller <nisse at lysator.liu.se>
date: Wed Jan 11 22:39:38 2012 +0100
description:
Implemented mpz_ui_sub.
details: /var/hg/gmp-proj/mini-gmp/rev/eb7a3053e12a
changeset: 62:eb7a3053e12a
user: Niels M?ller <nisse at lysator.liu.se>
date: Wed Jan 11 22:49:33 2012 +0100
description:
Implemented mpz_init2. In mpz_init, omit initialization of the low
limb.
diffstat:
mini-gmp.c | 34 ++++++++++++++++++++++++++++++++--
mini-gmp.h | 2 ++
2 files changed, 34 insertions(+), 2 deletions(-)
diffs (78 lines):
diff -r 44e854485004 -r eb7a3053e12a mini-gmp.c
--- a/mini-gmp.c Tue Jan 10 09:26:11 2012 +0100
+++ b/mini-gmp.c Wed Jan 11 22:49:33 2012 +0100
@@ -37,8 +37,15 @@
mpz_divisible_p
mpz_divisible_ui_p
mpz_export
+ mpz_fdiv_q_2exp
+ mpz_fdiv_r_2exp
+ mpz_import
+ mpz_lcm
mpz_lcm_ui
- */
+ mpz_scan0
+ mpz_scan1.
+ mpz_ui_sub
+*/
#include <assert.h>
#include <ctype.h>
@@ -1252,7 +1259,21 @@
r->_mp_alloc = 1;
r->_mp_size = 0;
r->_mp_d = gmp_xalloc_limbs (1);
- r->_mp_d[0] = 0;
+}
+
+/* The utility of this function is a bit limited, since many functions
+ assings the result variable using mpz_swap. */
+void
+mpz_init2 (mpz_t r, mp_bitcnt_t bits)
+{
+ mp_size_t rn;
+
+ bits -= (bits != 0); /* Round down, except if 0 */
+ rn = 1 + bits / GMP_LIMB_BITS;
+
+ r->_mp_alloc = rn;
+ r->_mp_size = 0;
+ r->_mp_d = gmp_xalloc_limbs (1);
}
void
@@ -1763,6 +1784,15 @@
r->_mp_size = mpz_abs_sub_ui (r, a, b);
}
+void
+mpz_ui_sub (mpz_t r, unsigned long a, const mpz_t b)
+{
+ if (b->_mp_size < 0)
+ r->_mp_size = mpz_abs_add_ui (r, b, a);
+ else
+ r->_mp_size = -mpz_abs_sub_ui (r, b, a);
+}
+
static mp_size_t
mpz_abs_add (mpz_t r, const mpz_t a, const mpz_t b)
{
diff -r 44e854485004 -r eb7a3053e12a mini-gmp.h
--- a/mini-gmp.h Tue Jan 10 09:26:11 2012 +0100
+++ b/mini-gmp.h Wed Jan 11 22:49:33 2012 +0100
@@ -84,6 +84,7 @@
mp_size_t mpn_set_str (mp_ptr, const unsigned char *, size_t, int);
void mpz_init (mpz_t);
+void mpz_init2 (mpz_t, mp_bitcnt_t);
void mpz_clear (mpz_t);
#define mpz_odd_p(z) (((z)->_mp_size != 0) & (int) (z)->_mp_d[0])
@@ -104,6 +105,7 @@
void mpz_add_ui (mpz_t, const mpz_t, unsigned long);
void mpz_add (mpz_t, const mpz_t, const mpz_t);
void mpz_sub_ui (mpz_t, const mpz_t, unsigned long);
+void mpz_ui_sub (mpz_t, unsigned long, const mpz_t);
void mpz_sub (mpz_t, const mpz_t, const mpz_t);
void mpz_mul_si (mpz_t, const mpz_t, long int);
More information about the gmp-commit
mailing list