summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2018-04-25 15:06:34 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2018-04-25 15:06:34 +0000
commit0ba13038d17723e3297e1e80e0985c8bd260576d (patch)
treedcdf28daee753331d5d4ac10eadd0ffc76913b80
parentdc5c66571ff603f86c3191e614b2bc80a83a8887 (diff)
downloadmpfr-0ba13038d17723e3297e1e80e0985c8bd260576d.tar.gz
[src/gmp_op.c] Fixed bug in mpfr_cmp_q when the denominator of the
mpq_t argument is 0. [tests/tgmpop.c] Added tests. (merged changesets r12499,12502 from the trunk) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/4.0@12664 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/gmp_op.c2
-rw-r--r--tests/tgmpop.c49
2 files changed, 50 insertions, 1 deletions
diff --git a/src/gmp_op.c b/src/gmp_op.c
index dd3165195..eab65479c 100644
--- a/src/gmp_op.c
+++ b/src/gmp_op.c
@@ -452,7 +452,7 @@ mpfr_cmp_q (mpfr_srcptr x, mpq_srcptr q)
mpfr_prec_t p;
MPFR_SAVE_EXPO_DECL (expo);
- if (MPFR_UNLIKELY (mpq_denref (q) == 0))
+ if (MPFR_UNLIKELY (mpz_sgn (mpq_denref (q)) == 0))
{
/* q is an infinity or NaN */
mpfr_init2 (t, 2);
diff --git a/tests/tgmpop.c b/tests/tgmpop.c
index e5cf87619..27a169026 100644
--- a/tests/tgmpop.c
+++ b/tests/tgmpop.c
@@ -341,6 +341,55 @@ test_cmp_q (mpfr_prec_t pmin, mpfr_prec_t pmax, int nmax)
}
}
}
+
+ /* check for y = 1/0 */
+ mpz_set_ui (mpq_numref (y), 1);
+ mpz_set_ui (mpq_denref (y), 0);
+ mpfr_set_ui (x, 1, MPFR_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_q (x, y) < 0);
+ mpfr_set_inf (x, -1);
+ MPFR_ASSERTN(mpfr_cmp_q (x, y) < 0);
+ mpfr_set_inf (x, +1);
+ MPFR_ASSERTN(mpfr_cmp_q (x, y) == 0);
+ mpfr_set_nan (x);
+ mpfr_clear_erangeflag ();
+ MPFR_ASSERTN(mpfr_cmp_q (x, y) == 0);
+ MPFR_ASSERTN(mpfr_erangeflag_p ());
+
+ /* check for y = -1/0 */
+ mpz_set_si (mpq_numref (y), -1);
+ mpz_set_ui (mpq_denref (y), 0);
+ mpfr_set_ui (x, 1, MPFR_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_q (x, y) > 0);
+ mpfr_set_inf (x, -1);
+ MPFR_ASSERTN(mpfr_cmp_q (x, y) == 0);
+ mpfr_set_inf (x, +1);
+ MPFR_ASSERTN(mpfr_cmp_q (x, y) > 0);
+ mpfr_set_nan (x);
+ mpfr_clear_erangeflag ();
+ MPFR_ASSERTN(mpfr_cmp_q (x, y) == 0);
+ MPFR_ASSERTN(mpfr_erangeflag_p ());
+
+ /* check for y = 0/0 */
+ mpz_set_ui (mpq_numref (y), 0);
+ mpz_set_ui (mpq_denref (y), 0);
+ mpfr_set_ui (x, 1, MPFR_RNDN);
+ mpfr_clear_erangeflag ();
+ MPFR_ASSERTN(mpfr_cmp_q (x, y) == 0);
+ MPFR_ASSERTN(mpfr_erangeflag_p ());
+ mpfr_set_inf (x, -1);
+ mpfr_clear_erangeflag ();
+ MPFR_ASSERTN(mpfr_cmp_q (x, y) == 0);
+ MPFR_ASSERTN(mpfr_erangeflag_p ());
+ mpfr_set_inf (x, +1);
+ mpfr_clear_erangeflag ();
+ MPFR_ASSERTN(mpfr_cmp_q (x, y) == 0);
+ MPFR_ASSERTN(mpfr_erangeflag_p ());
+ mpfr_set_nan (x);
+ mpfr_clear_erangeflag ();
+ MPFR_ASSERTN(mpfr_cmp_q (x, y) == 0);
+ MPFR_ASSERTN(mpfr_erangeflag_p ());
+
mpq_clear (y);
mpfr_clear (x);
mpfr_clear (z);