summaryrefslogtreecommitdiff
path: root/tests/tget_q.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2017-12-09 21:59:21 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2017-12-09 21:59:21 +0000
commit4b96c94982e139915c74515ca987bc88c51a454f (patch)
treeffda61acddc0687fded4a4442a748bed549cb0d2 /tests/tget_q.c
parent0512b1c5116267a1e64d8239dad3c6de3f0f359f (diff)
downloadmpfr-4b96c94982e139915c74515ca987bc88c51a454f.tar.gz
[src/get_q.c] make result of mpfr_get_q in canonical form
[tests/tget_q.c] added non-regression test git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@11951 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tget_q.c')
-rw-r--r--tests/tget_q.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/tget_q.c b/tests/tget_q.c
index fa2d5bb8b..8a577ac36 100644
--- a/tests/tget_q.c
+++ b/tests/tget_q.c
@@ -100,6 +100,38 @@ random_tests (void)
mpfr_clear (g);
}
+/* Check results are in canonical form.
+ See https://sympa.inria.fr/sympa/arc/mpfr/2017-12/msg00029.html */
+static void
+check_canonical (void)
+{
+ mpfr_t x;
+ mpq_t q;
+ mpz_t z;
+
+ mpfr_init2 (x, 53);
+ mpfr_set_ui (x, 3, MPFR_RNDN);
+ mpq_init (q);
+ mpfr_get_q (q, x);
+ /* check the denominator is positive */
+ if (mpz_sgn (mpq_denref (q)) <= 0)
+ {
+ printf ("Error, the denominator of mpfr_get_q should be positive\n");
+ MPFR_ASSERTN (0);
+ }
+ mpz_init (z);
+ mpz_gcd (z, mpq_numref (q), mpq_denref (q));
+ /* check the numerator and denominator are coprime */
+ if (mpz_cmp_ui (z, 1) != 0)
+ {
+ printf ("Error, numerator and denominator of mpfr_get_q should be coprime\n");
+ MPFR_ASSERTN (0);
+ }
+ mpfr_clear (x);
+ mpq_clear (q);
+ mpz_clear (z);
+}
+
int
main (void)
{
@@ -108,6 +140,8 @@ main (void)
special ();
random_tests ();
+ check_canonical ();
+
tests_end_mpfr ();
return 0;
}