[Gmp-commit] /var/hg/gmp: 2 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Sat Jan 12 15:40:11 CET 2013
details: /var/hg/gmp/rev/251b0b56f673
changeset: 15261:251b0b56f673
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sat Jan 12 12:46:10 2013 +0100
description:
mini-gmp/mini-gmp.c: New macro NEG_CAST, used by mpz_*_si functions.
details: /var/hg/gmp/rev/ff47d4b1f1f2
changeset: 15262:ff47d4b1f1f2
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sat Jan 12 13:03:04 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_set_si, mpz_cmp_si): Simplify.
diffstat:
ChangeLog | 6 ++++++
mini-gmp/mini-gmp.c | 51 ++++++++++++++++-----------------------------------
2 files changed, 22 insertions(+), 35 deletions(-)
diffs (104 lines):
diff -r e60d1a18d8a9 -r ff47d4b1f1f2 ChangeLog
--- a/ChangeLog Sat Jan 12 12:09:23 2013 +0100
+++ b/ChangeLog Sat Jan 12 13:03:04 2013 +0100
@@ -7,6 +7,12 @@
* mini-gmp/mini-gmp.c (mpz_mul_si): Simplify.
(mpz_mul_ui, mpz_mul, mpz_div_qr): Replace init+REALLOC with init2.
+ * mini-gmp/mini-gmp.c (NEG_CAST): New macro.
+ (mpz_mul_si, mpz_set_si, mpz_cmp_si): Use NEG_CAST.
+
+ * mini-gmp/mini-gmp.c (mpz_set_si, mpz_cmp_si): Simplify by using
+ the _ui variant.
+
2013-01-10 Marco Bodrato <bodrato at mail.dm.unipi.it>
* mpz/export.c: Less restrictive ASSERTs.
diff -r e60d1a18d8a9 -r ff47d4b1f1f2 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c Sat Jan 12 12:09:23 2013 +0100
+++ b/mini-gmp/mini-gmp.c Sat Jan 12 13:03:04 2013 +0100
@@ -55,6 +55,7 @@
#define GMP_ULONG_HIGHBIT ((unsigned long) 1 << (GMP_ULONG_BITS - 1))
#define GMP_ABS(x) ((x) >= 0 ? (x) : -(x))
+#define NEG_CAST(T,x) (-((T)((x) + 1) - 1))
#define GMP_MIN(a, b) ((a) < (b) ? (a) : (b))
#define GMP_MAX(a, b) ((a) > (b) ? (a) : (b))
@@ -1342,18 +1343,13 @@
void
mpz_set_si (mpz_t r, signed long int x)
{
- if (x > 0)
- {
- r->_mp_size = 1;
- r->_mp_d[0] = x;
- }
- else if (x < 0)
+ if (x >= 0)
+ mpz_set_ui (r, x);
+ else /* (x < 0) */
{
r->_mp_size = -1;
- r->_mp_d[0] = -x;
+ r->_mp_d[0] = NEG_CAST (unsigned long int, x);
}
- else
- r->_mp_size = 0;
}
void
@@ -1628,34 +1624,19 @@
{
mp_size_t usize = u->_mp_size;
- if (usize > 1)
+ if (usize < -1)
+ return -1;
+ else if (v >= 0)
+ return mpz_cmp_ui (u, v);
+ else if (usize >= 0)
return 1;
- else if (usize < -1)
- return -1;
- else if (usize == 0)
- {
- if (v > 0)
- return -1;
- else if (v < 0)
- return 1;
- }
- else
+ else /* usize == -1 */
{
mp_limb_t ul = u->_mp_d[0];
- if (usize == 1)
- {
- if (v <= 0 || (mp_limb_t) v < ul)
- return 1;
- else if ((mp_limb_t) v > ul)
- return -1;
- }
- else /* usize == -1 */
- {
- if (v >= 0 || (mp_limb_t) -v < ul)
- return -1;
- else if ((mp_limb_t) -v > ul)
- return 1;
- }
+ if ((mp_limb_t)NEG_CAST (unsigned long int, v) < ul)
+ return -1;
+ else if ( (mp_limb_t)NEG_CAST (unsigned long int, v) > ul)
+ return 1;
}
return 0;
}
@@ -1908,7 +1889,7 @@
{
if (v < 0)
{
- mpz_mul_ui (r, u, -((unsigned long int)(v + 1) - 1)); /* ABS_CAST */
+ mpz_mul_ui (r, u, NEG_CAST (unsigned long int, v));
mpz_neg (r, r);
}
else
More information about the gmp-commit
mailing list