summaryrefslogtreecommitdiff
path: root/mpq
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2014-07-30 00:23:26 +0200
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2014-07-30 00:23:26 +0200
commitca18a5538da0c12009431fd1ae0d6346e7af0ecd (patch)
tree7748c7ccddd1d2798a9d360b6fa2f064fab2bf9f /mpq
parent507304578041c6dc564b125828b88e8601010ca8 (diff)
downloadgmp-ca18a5538da0c12009431fd1ae0d6346e7af0ecd.tar.gz
mpq/cmp_[su]i.c: Remove a branch.
Diffstat (limited to 'mpq')
-rw-r--r--mpq/cmp_si.c26
-rw-r--r--mpq/cmp_ui.c11
2 files changed, 14 insertions, 23 deletions
diff --git a/mpq/cmp_si.c b/mpq/cmp_si.c
index 0a31fe8c9..f21382e5b 100644
--- a/mpq/cmp_si.c
+++ b/mpq/cmp_si.c
@@ -1,6 +1,6 @@
/* _mpq_cmp_si -- compare mpq and long/ulong fraction.
-Copyright 2001, 2013 Free Software Foundation, Inc.
+Copyright 2001, 2013, 2014 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -42,26 +42,20 @@ _mpq_cmp_si (mpq_srcptr q, long n, unsigned long d)
/* need canonical sign to get right result */
ASSERT (SIZ(DEN(q)) > 0);
+ if (n >= 0)
+ return _mpq_cmp_ui (q, n, d);
if (SIZ(NUM(q)) >= 0)
{
- if (n >= 0)
- return _mpq_cmp_ui (q, n, d); /* >=0 cmp >=0 */
- else
- return 1; /* >=0 cmp <0 */
+ return 1; /* >=0 cmp <0 */
}
else
{
- if (n >= 0)
- return -1; /* <0 cmp >=0 */
- else
- {
- mpq_t qabs;
- SIZ(NUM(qabs)) = ABSIZ(NUM(q));
- PTR(NUM(qabs)) = PTR(NUM(q));
- SIZ(DEN(qabs)) = SIZ(DEN(q));
- PTR(DEN(qabs)) = PTR(DEN(q));
+ mpq_t qabs;
+ SIZ(NUM(qabs)) = -SIZ(NUM(q));
+ PTR(NUM(qabs)) = PTR(NUM(q));
+ SIZ(DEN(qabs)) = SIZ(DEN(q));
+ PTR(DEN(qabs)) = PTR(DEN(q));
- return - _mpq_cmp_ui (qabs, NEG_CAST (unsigned long, n), d); /* <0 cmp <0 */
- }
+ return - _mpq_cmp_ui (qabs, NEG_CAST (unsigned long, n), d); /* <0 cmp <0 */
}
}
diff --git a/mpq/cmp_ui.c b/mpq/cmp_ui.c
index a2e2d8ca8..01857a088 100644
--- a/mpq/cmp_ui.c
+++ b/mpq/cmp_ui.c
@@ -2,7 +2,7 @@
negative based on if U > V, U == V, or U < V. Vn and Vd may have
common factors.
-Copyright 1993, 1994, 1996, 2000-2003, 2005 Free Software Foundation, Inc.
+Copyright 1993, 1994, 1996, 2000-2003, 2005, 2014 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -63,12 +63,10 @@ _mpq_cmp_ui (const mpq_t op1, unsigned long int num2, unsigned long int den2)
if (UNLIKELY (den2 == 0))
DIVIDE_BY_ZERO;
- if (num1_size == 0)
- return -(num2 != 0);
- if (num1_size < 0)
- return num1_size;
if (num2 == 0)
return num1_size;
+ if (num1_size <= 0)
+ return -1;
/* NUM1 x DEN2 is either TMP1_SIZE limbs or TMP1_SIZE-1 limbs.
Same for NUM1 x DEN1 with respect to TMP2_SIZE. */
@@ -80,8 +78,7 @@ _mpq_cmp_ui (const mpq_t op1, unsigned long int num2, unsigned long int den2)
return -num1_size;
TMP_MARK;
- tmp1_ptr = TMP_ALLOC_LIMBS (num1_size + 1);
- tmp2_ptr = TMP_ALLOC_LIMBS (den1_size + 1);
+ TMP_ALLOC_LIMBS_2 (tmp1_ptr, num1_size + 1, tmp2_ptr, den1_size + 1);
cy_limb = mpn_mul_1 (tmp1_ptr, PTR(NUM(op1)), num1_size,
(mp_limb_t) den2);