[Gmp-commit] /var/hg/gmp-5.0: (ABS_CAST): New macro.
mercurial at gmplib.org
mercurial at gmplib.org
Thu Feb 9 18:22:20 CET 2012
details: /var/hg/gmp-5.0/rev/4849e62500a9
changeset: 13565:4849e62500a9
user: Torbjorn Granlund <tege at gmplib.org>
date: Thu Feb 09 18:22:15 2012 +0100
description:
(ABS_CAST): New macro.
diffstat:
ChangeLog | 16 ++++++++++++++--
gmp-impl.h | 4 +++-
mpf/cmp_si.c | 11 ++++++-----
mpf/get_si.c | 2 +-
mpf/iset_si.c | 2 +-
mpf/set_si.c | 2 +-
mpq/set_si.c | 2 +-
mpz/cmp_si.c | 7 ++++---
mpz/get_si.c | 4 ++--
mpz/iset_si.c | 2 +-
mpz/mul_i.h | 2 +-
mpz/set_si.c | 2 +-
12 files changed, 36 insertions(+), 20 deletions(-)
diffs (217 lines):
diff -r 702aa1847945 -r 4849e62500a9 ChangeLog
--- a/ChangeLog Thu Feb 09 13:26:40 2012 +0100
+++ b/ChangeLog Thu Feb 09 18:22:15 2012 +0100
@@ -1,7 +1,19 @@
+2012-02-09 Marc Glisse <marc.glisse at inria.fr>
+
+ * gmp-impl.h (ABS_CAST): New macro.
+ * mpf/cmp_si.c: Use ABS_CAST.
+ * mpf/get_si.c: Use ABS_CAST.
+ * mpf/iset_si.c: Use ABS_CAST.
+ * mpf/set_si.c: Use ABS_CAST.
+ * mpq/set_si.c: Use ABS_CAST.
+ * mpz/cmp_si.c: Use ABS_CAST.
+ * mpz/get_si.c: Use ABS_CAST.
+ * mpz/iset_si.c: Use ABS_CAST.
+ * mpz/mul_i.h: Use ABS_CAST.
+ * mpz/set_si.c: Use ABS_CAST.
+
2012-02-09 Torbjorn Granlund <tege at gmplib.org>
- * Version 5.0.4 released.
-
* gmp-h.in (__GNU_MP_VERSION_PATCHLEVEL): Bump.
* Makefile.am (LIBGMP_LT_*, LIBGMPXX_LT_*, LIBMP_LT_*):
diff -r 702aa1847945 -r 4849e62500a9 gmp-impl.h
--- a/gmp-impl.h Thu Feb 09 13:26:40 2012 +0100
+++ b/gmp-impl.h Thu Feb 09 18:22:15 2012 +0100
@@ -4,7 +4,8 @@
BE SUBJECT TO INCOMPATIBLE CHANGES IN FUTURE GNU MP RELEASES.
Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003,
-2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation,
+Inc.
This file is part of the GNU MP Library.
@@ -478,6 +479,7 @@
#define UNLIKELY(cond) __GMP_UNLIKELY(cond)
#define ABS(x) ((x) >= 0 ? (x) : -(x))
+#define ABS_CAST(T,x) ((x) >= 0 ? (T)(x) : -((T)((x) + 1) - 1))
#undef MIN
#define MIN(l,o) ((l) < (o) ? (l) : (o))
#undef MAX
diff -r 702aa1847945 -r 4849e62500a9 mpf/cmp_si.c
--- a/mpf/cmp_si.c Thu Feb 09 13:26:40 2012 +0100
+++ b/mpf/cmp_si.c Thu Feb 09 18:22:15 2012 +0100
@@ -29,6 +29,7 @@
mp_exp_t uexp;
mp_limb_t ulimb;
int usign;
+ unsigned long abs_vval;
uexp = u->_mp_exp;
usize = u->_mp_size;
@@ -55,13 +56,13 @@
usign = usize >= 0 ? 1 : -1;
usize = ABS (usize);
- vval = ABS (vval);
+ abs_vval = ABS_CAST (unsigned long, vval);
/* 2. Are the exponents different (V's exponent == 1)? */
#if GMP_NAIL_BITS != 0
- if (uexp > 1 + ((unsigned long) vval > GMP_NUMB_MAX))
+ if (uexp > 1 + (abs_vval > GMP_NUMB_MAX))
return usign;
- if (uexp < 1 + ((unsigned long) vval > GMP_NUMB_MAX))
+ if (uexp < 1 + (abs_vval > GMP_NUMB_MAX))
return -usign;
#else
if (uexp > 1)
@@ -85,9 +86,9 @@
usize--;
/* 3. Compare the most significant mantissa limb with V. */
- if (ulimb > (unsigned long) vval)
+ if (ulimb > abs_vval)
return usign;
- else if (ulimb < (unsigned long) vval)
+ else if (ulimb < abs_vval)
return -usign;
/* Ignore zeroes at the low end of U. */
diff -r 702aa1847945 -r 4849e62500a9 mpf/get_si.c
--- a/mpf/get_si.c Thu Feb 09 13:26:40 2012 +0100
+++ b/mpf/get_si.c Thu Feb 09 18:22:15 2012 +0100
@@ -72,5 +72,5 @@
return fl & LONG_MAX;
else
/* this form necessary to correctly handle -0x80..00 */
- return ~ ((fl - 1) & LONG_MAX);
+ return -1 - (long) ((fl - 1) & LONG_MAX);
}
diff -r 702aa1847945 -r 4849e62500a9 mpf/iset_si.c
--- a/mpf/iset_si.c Thu Feb 09 13:26:40 2012 +0100
+++ b/mpf/iset_si.c Thu Feb 09 18:22:15 2012 +0100
@@ -31,7 +31,7 @@
r->_mp_prec = prec;
r->_mp_d = (mp_ptr) (*__gmp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB);
- vl = (mp_limb_t) (unsigned long int) (val >= 0 ? val : -val);
+ vl = (mp_limb_t) ABS_CAST (unsigned long int, val);
r->_mp_d[0] = vl & GMP_NUMB_MASK;
size = vl != 0;
diff -r 702aa1847945 -r 4849e62500a9 mpf/set_si.c
--- a/mpf/set_si.c Thu Feb 09 13:26:40 2012 +0100
+++ b/mpf/set_si.c Thu Feb 09 18:22:15 2012 +0100
@@ -27,7 +27,7 @@
mp_size_t size;
mp_limb_t vl;
- vl = (mp_limb_t) (unsigned long int) (val >= 0 ? val : -val);
+ vl = (mp_limb_t) ABS_CAST (unsigned long int, val);
dest->_mp_d[0] = vl & GMP_NUMB_MASK;
size = vl != 0;
diff -r 702aa1847945 -r 4849e62500a9 mpq/set_si.c
--- a/mpq/set_si.c Thu Feb 09 13:26:40 2012 +0100
+++ b/mpq/set_si.c Thu Feb 09 18:22:15 2012 +0100
@@ -35,7 +35,7 @@
return;
}
- abs_num = ABS (num);
+ abs_num = ABS_CAST (unsigned long, num);
if (num == 0)
{
diff -r 702aa1847945 -r 4849e62500a9 mpz/cmp_si.c
--- a/mpz/cmp_si.c Thu Feb 09 13:26:40 2012 +0100
+++ b/mpz/cmp_si.c Thu Feb 09 18:22:15 2012 +0100
@@ -28,6 +28,7 @@
mp_size_t usize = u->_mp_size;
mp_size_t vsize;
mp_limb_t u_digit;
+ unsigned long int absv_digit = (unsigned long int) v_digit;
#if GMP_NAIL_BITS != 0
/* FIXME. This isn't very pretty. */
@@ -45,7 +46,7 @@
else if (v_digit < 0)
{
vsize = -1;
- v_digit = -v_digit;
+ absv_digit = -absv_digit;
}
if (usize != vsize)
@@ -56,10 +57,10 @@
u_digit = u->_mp_d[0];
- if (u_digit == (mp_limb_t) (unsigned long) v_digit)
+ if (u_digit == (mp_limb_t) absv_digit)
return 0;
- if (u_digit > (mp_limb_t) (unsigned long) v_digit)
+ if (u_digit > (mp_limb_t) absv_digit)
return usize;
else
return -usize;
diff -r 702aa1847945 -r 4849e62500a9 mpz/get_si.c
--- a/mpz/get_si.c Thu Feb 09 13:26:40 2012 +0100
+++ b/mpz/get_si.c Thu Feb 09 18:22:15 2012 +0100
@@ -34,10 +34,10 @@
#endif
if (size > 0)
- return (long) zl & LONG_MAX;
+ return zl & LONG_MAX;
else if (size < 0)
/* This expression is necessary to properly handle 0x80000000 */
- return ~(((long) zl - 1L) & LONG_MAX);
+ return -1 - (long) ((zl - 1) & LONG_MAX);
else
return 0;
}
diff -r 702aa1847945 -r 4849e62500a9 mpz/iset_si.c
--- a/mpz/iset_si.c Thu Feb 09 13:26:40 2012 +0100
+++ b/mpz/iset_si.c Thu Feb 09 18:22:15 2012 +0100
@@ -31,7 +31,7 @@
dest->_mp_alloc = 1;
dest->_mp_d = (mp_ptr) (*__gmp_allocate_func) (BYTES_PER_MP_LIMB);
- vl = (mp_limb_t) (unsigned long int) (val >= 0 ? val : -val);
+ vl = (mp_limb_t) ABS_CAST (unsigned long int, val);
dest->_mp_d[0] = vl & GMP_NUMB_MASK;
size = vl != 0;
diff -r 702aa1847945 -r 4849e62500a9 mpz/mul_i.h
--- a/mpz/mul_i.h Thu Feb 09 13:26:40 2012 +0100
+++ b/mpz/mul_i.h Thu Feb 09 18:22:15 2012 +0100
@@ -26,7 +26,7 @@
#ifdef OPERATION_mul_si
#define FUNCTION mpz_mul_si
#define MULTIPLICAND_UNSIGNED
-#define MULTIPLICAND_ABS(x) ((unsigned long) ABS(x))
+#define MULTIPLICAND_ABS(x) ABS_CAST(unsigned long, (x))
#endif
#ifdef OPERATION_mul_ui
diff -r 702aa1847945 -r 4849e62500a9 mpz/set_si.c
--- a/mpz/set_si.c Thu Feb 09 13:26:40 2012 +0100
+++ b/mpz/set_si.c Thu Feb 09 18:22:15 2012 +0100
@@ -27,7 +27,7 @@
mp_size_t size;
mp_limb_t vl;
- vl = (mp_limb_t) (unsigned long int) (val >= 0 ? val : -val);
+ vl = (mp_limb_t) ABS_CAST (unsigned long int, val);
dest->_mp_d[0] = vl & GMP_NUMB_MASK;
size = vl != 0;
More information about the gmp-commit
mailing list