[Gmp-commit] /var/hg/gmp: 3 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Sat May 30 03:57:20 UTC 2015
details: /var/hg/gmp/rev/9cf1ca412141
changeset: 16658:9cf1ca412141
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sat May 30 05:45:29 2015 +0200
description:
mpf/cmp_[su]i.c: Use macros, remove branches, correct nails.
details: /var/hg/gmp/rev/dd251f71f6fa
changeset: 16659:dd251f71f6fa
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sat May 30 05:48:51 2015 +0200
description:
mpf/int_p.c: Use a simpler loop to ignore zero limbs.
details: /var/hg/gmp/rev/2a5e2ea2e66c
changeset: 16660:2a5e2ea2e66c
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sat May 30 05:52:50 2015 +0200
description:
ChangeLog
diffstat:
ChangeLog | 6 ++++++
mpf/cmp_si.c | 46 +++++++++++++++++++---------------------------
mpf/cmp_ui.c | 50 +++++++++++++++++++-------------------------------
mpf/int_p.c | 12 +++++++++---
4 files changed, 53 insertions(+), 61 deletions(-)
diffs (225 lines):
diff -r e9067f75e42a -r 2a5e2ea2e66c ChangeLog
--- a/ChangeLog Thu May 28 11:42:33 2015 +0200
+++ b/ChangeLog Sat May 30 05:52:50 2015 +0200
@@ -1,3 +1,9 @@
+2015-05-30 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+ * mpf/cmp_ui.c: Use macros, remove branches, correct nails.
+ * mpf/cmp_si.c: Likewise.
+ * mpf/int_p.c: Use a simpler loop to ignore zero limbs.
+
2015-05-28 Niels Möller <nisse at lysator.liu.se>
* doc/gmp.texi (Low-level Functions): Document mpn_divexact_1 and
diff -r e9067f75e42a -r 2a5e2ea2e66c mpf/cmp_si.c
--- a/mpf/cmp_si.c Thu May 28 11:42:33 2015 +0200
+++ b/mpf/cmp_si.c Sat May 30 05:52:50 2015 +0200
@@ -1,6 +1,7 @@
/* mpf_cmp_si -- Compare a float with a signed integer.
-Copyright 1993-1995, 1999-2002, 2004, 2012 Free Software Foundation, Inc.
+Copyright 1993-1995, 1999-2002, 2004, 2012, 2015 Free Software
+Foundation, Inc.
This file is part of the GNU MP Library.
@@ -41,8 +42,7 @@
int usign;
unsigned long abs_vval;
- uexp = u->_mp_exp;
- usize = u->_mp_size;
+ usize = SIZ (u);
/* 1. Are the signs different? */
if ((usize < 0) == (vval < 0)) /* don't use xor, type size may differ */
@@ -64,49 +64,41 @@
/* U and V have the same sign and are both non-zero. */
+ /* 2. Are the exponents different (V's exponent == 1)? */
+ uexp = EXP (u);
usign = usize >= 0 ? 1 : -1;
usize = ABS (usize);
abs_vval = ABS_CAST (unsigned long, vval);
- /* 2. Are the exponents different (V's exponent == 1)? */
#if GMP_NAIL_BITS != 0
- if (uexp > 1 + (abs_vval > GMP_NUMB_MAX))
- return usign;
- if (uexp < 1 + (abs_vval > GMP_NUMB_MAX))
- return -usign;
+ if (uexp != 1 + (abs_vval > GMP_NUMB_MAX))
+ return (uexp < 1 + (abs_vval > GMP_NUMB_MAX)) ? -usign : usign;
#else
- if (uexp > 1)
- return usign;
- if (uexp < 1)
- return -usign;
+ if (uexp != 1)
+ return (uexp < 1) ? -usign : usign;
#endif
- up = u->_mp_d;
+ up = PTR (u);
- ulimb = up[usize - 1];
+ ASSERT (usize > 0);
+ ulimb = up[--usize];
#if GMP_NAIL_BITS != 0
- if (usize >= 2 && uexp == 2)
+ if (uexp == 2)
{
if ((ulimb >> GMP_NAIL_BITS) != 0)
return usign;
- ulimb = (ulimb << GMP_NUMB_BITS) | up[usize - 2];
- usize--;
+ ulimb = (ulimb << GMP_NUMB_BITS);
+ if (usize != 0) ulimb |= up[--usize];
}
#endif
- usize--;
/* 3. Compare the most significant mantissa limb with V. */
- if (ulimb > abs_vval)
- return usign;
- else if (ulimb < abs_vval)
- return -usign;
+ if (ulimb != abs_vval)
+ return (ulimb < abs_vval) ? -usign : usign;
/* Ignore zeroes at the low end of U. */
- while (*up == 0)
- {
- up++;
- usize--;
- }
+ for (; *up == 0; ++up)
+ --usize;
/* 4. Now, if the number of limbs are different, we have a difference
since we have made sure the trailing limbs are not zero. */
diff -r e9067f75e42a -r 2a5e2ea2e66c mpf/cmp_ui.c
--- a/mpf/cmp_ui.c Thu May 28 11:42:33 2015 +0200
+++ b/mpf/cmp_ui.c Sat May 30 05:52:50 2015 +0200
@@ -1,6 +1,6 @@
/* mpf_cmp_ui -- Compare a float with an unsigned integer.
-Copyright 1993-1995, 1999, 2001, 2002 Free Software Foundation, Inc.
+Copyright 1993-1995, 1999, 2001, 2002, 2015 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -39,8 +39,7 @@
mp_exp_t uexp;
mp_limb_t ulimb;
- uexp = u->_mp_exp;
- usize = u->_mp_size;
+ usize = SIZ (u);
/* 1. Is U negative? */
if (usize < 0)
@@ -51,50 +50,39 @@
return usize != 0;
/* 2. Are the exponents different (V's exponent == 1)? */
+ uexp = EXP (u);
+
#if GMP_NAIL_BITS != 0
- if (uexp > 1 + (vval > GMP_NUMB_MAX))
- return 1;
- if (uexp < 1 + (vval > GMP_NUMB_MAX))
- return -1;
+ if (uexp != 1 + (vval > GMP_NUMB_MAX))
+ return (uexp < 1 + (vval > GMP_NUMB_MAX)) ? -1 : 1;
#else
- if (uexp > 1)
- return 1;
- if (uexp < 1)
- return -1;
+ if (uexp != 1)
+ return (uexp < 1) ? -1 : 1;
#endif
- up = u->_mp_d;
+ up = PTR (u);
- ulimb = up[usize - 1];
+ ASSERT (usize > 0);
+ ulimb = up[--usize];
#if GMP_NAIL_BITS != 0
- if (usize >= 2 && uexp == 2)
+ if (uexp == 2)
{
if ((ulimb >> GMP_NAIL_BITS) != 0)
return 1;
- ulimb = (ulimb << GMP_NUMB_BITS) | up[usize - 2];
- usize--;
+ ulimb = (ulimb << GMP_NUMB_BITS);
+ if (usize != 0) ulimb |= up[--usize];
}
#endif
- usize--;
/* 3. Compare the most significant mantissa limb with V. */
- if (ulimb > vval)
- return 1;
- else if (ulimb < vval)
- return -1;
+ if (ulimb != vval)
+ return (ulimb < vval) ? -1 : 1;
/* Ignore zeroes at the low end of U. */
- while (*up == 0)
- {
- up++;
- usize--;
- }
+ for (; *up == 0; ++up)
+ --usize;
/* 4. Now, if the number of limbs are different, we have a difference
since we have made sure the trailing limbs are not zero. */
- if (usize > 0)
- return 1;
-
- /* Wow, we got zero even if we tried hard to avoid it. */
- return 0;
+ return (usize > 0);
}
diff -r e9067f75e42a -r 2a5e2ea2e66c mpf/int_p.c
--- a/mpf/int_p.c Thu May 28 11:42:33 2015 +0200
+++ b/mpf/int_p.c Sat May 30 05:52:50 2015 +0200
@@ -1,7 +1,7 @@
/* mpf_integer_p -- test whether an mpf is an integer */
/*
-Copyright 2001, 2002, 2014 Free Software Foundation, Inc.
+Copyright 2001, 2002, 2014-2015 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -36,6 +36,7 @@
int
mpf_integer_p (mpf_srcptr f) __GMP_NOTHROW
{
+ mp_srcptr fp;
mp_exp_t exp;
mp_size_t size;
@@ -44,7 +45,12 @@
if (exp <= 0)
return (size == 0); /* zero is an integer,
others have only fraction limbs */
+ size = ABS (size);
- /* any fraction limbs must be zero */
- return mpn_zero_p (PTR (f), ABS (size) - exp);
+ /* Ignore zeroes at the low end of F. */
+ for (fp = PTR (f); *fp == 0; ++fp)
+ --size;
+
+ /* no fraction limbs */
+ return size <= exp;
}
More information about the gmp-commit
mailing list