summaryrefslogtreecommitdiff
path: root/mpq
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2018-02-18 11:02:06 +0100
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2018-02-18 11:02:06 +0100
commitd842e0a4f59e776ad3caa0bcce7ca1ad3bc64e07 (patch)
treeb03599b1d7793531944c278be0d193476cfc7c96 /mpq
parent30d71014b7f96036ffbaff635ec6845d7f9f99cd (diff)
downloadgmp-d842e0a4f59e776ad3caa0bcce7ca1ad3bc64e07.tar.gz
mpq/cmp_ui.c: One more little shortcut comparing fractions to 1.
Diffstat (limited to 'mpq')
-rw-r--r--mpq/cmp_ui.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/mpq/cmp_ui.c b/mpq/cmp_ui.c
index b12881436..9d99a9a86 100644
--- a/mpq/cmp_ui.c
+++ b/mpq/cmp_ui.c
@@ -2,7 +2,8 @@
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, 2014 Free Software Foundation, Inc.
+Copyright 1993, 1994, 1996, 2000-2003, 2005, 2014, 2018 Free Software
+Foundation, Inc.
This file is part of the GNU MP Library.
@@ -68,11 +69,13 @@ _mpq_cmp_ui (mpq_srcptr op1, unsigned long int num2, unsigned long int den2)
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. */
- if (num1_size > den1_size + 1)
+ Same for NUM2 x DEN1 with respect to TMP2_SIZE. */
+ /* If frac2 <= 1 (i.e. num2 <= den2), shortcut with a simpler
+ condition: num1 > den1. Here we only test sizes. */
+ if (num1_size > den1_size + (num2 > den2))
/* NUM1 x DEN2 is surely larger in magnitude than NUM2 x DEN1. */
return num1_size;
- if (den1_size > num1_size + 1)
+ if (den1_size > num1_size + (den2 > num2))
/* NUM1 x DEN2 is surely smaller in magnitude than NUM2 x DEN1. */
return -num1_size;
@@ -89,8 +92,8 @@ _mpq_cmp_ui (mpq_srcptr op1, unsigned long int num2, unsigned long int den2)
tmp2_ptr[den1_size] = cy_limb;
tmp2_size = den1_size + (cy_limb != 0);
- cc = tmp1_size - tmp2_size != 0
- ? tmp1_size - tmp2_size : mpn_cmp (tmp1_ptr, tmp2_ptr, tmp1_size);
+ cc = tmp1_size - tmp2_size;
+ cc = cc != 0 ? cc : mpn_cmp (tmp1_ptr, tmp2_ptr, tmp1_size);
TMP_FREE;
return cc;
}