summaryrefslogtreecommitdiff
path: root/gmp/tests/mpq/t-get_d.c
diff options
context:
space:
mode:
Diffstat (limited to 'gmp/tests/mpq/t-get_d.c')
-rw-r--r--gmp/tests/mpq/t-get_d.c77
1 files changed, 27 insertions, 50 deletions
diff --git a/gmp/tests/mpq/t-get_d.c b/gmp/tests/mpq/t-get_d.c
index aa848e029c..f116189012 100644
--- a/gmp/tests/mpq/t-get_d.c
+++ b/gmp/tests/mpq/t-get_d.c
@@ -1,22 +1,22 @@
/* Test mpq_get_d and mpq_set_d
-Copyright 1991, 1993, 1994, 1996, 2000-2003, 2012, 2013 Free Software
+Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2002, 2003 Free Software
Foundation, Inc.
-This file is part of the GNU MP Library test suite.
+This file is part of the GNU MP Library.
-The GNU MP Library test suite is free software; you can redistribute it
-and/or modify it under the terms of the GNU General Public License as
-published by the Free Software Foundation; either version 3 of the License,
-or (at your option) any later version.
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
-The GNU MP Library test suite is distributed in the hope that it will be
-useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-Public License for more details.
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
-You should have received a copy of the GNU General Public License along with
-the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
+You should have received a copy of the GNU Lesser General Public License
+along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include <stdio.h>
#include <stdlib.h>
@@ -31,7 +31,7 @@ the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
/* VAX D floats only have an 8 bit signed exponent, so anything 2^128 or
bigger will overflow, that being 4 limbs. */
-#if defined (__vax) || defined (__vax__) && SIZE > 4
+#if defined (__vax__) && SIZE > 4
#undef SIZE
#define SIZE 4
#define EPSIZE 3
@@ -39,7 +39,7 @@ the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
#define EPSIZE SIZE
#endif
-void dump (mpq_t);
+void dump __GMP_PROTO ((mpq_t));
void
check_monotonic (int argc, char **argv)
@@ -153,63 +153,40 @@ my_ldexp (double d, int e)
}
}
-#define MAXEXP 500
-
-#if defined (__vax) || defined (__vax__)
-#undef MAXEXP
-#define MAXEXP 30
-#endif
-
void
check_random (int argc, char **argv)
{
- gmp_randstate_ptr rands = RANDS;
-
- double d;
+ double d, d2, nd, dd;
mpq_t q;
- mpz_t a, t;
- int exp;
-
+ mp_limb_t rp[LIMBS_PER_DOUBLE + 1];
int test, reps = 100000;
+ int i;
if (argc == 2)
reps = 100 * atoi (argv[1]);
mpq_init (q);
- mpz_init (a);
- mpz_init (t);
for (test = 0; test < reps; test++)
{
- mpz_rrandomb (a, rands, 53);
- mpz_urandomb (t, rands, 32);
- exp = mpz_get_ui (t) % (2*MAXEXP) - MAXEXP;
-
- d = my_ldexp (mpz_get_d (a), exp);
+ mpn_random2 (rp, LIMBS_PER_DOUBLE + 1);
+ d = 0.0;
+ for (i = LIMBS_PER_DOUBLE - 1; i >= 0; i--)
+ d = d * MP_BASE_AS_DOUBLE + rp[i];
+ d = my_ldexp (d, (int) (rp[LIMBS_PER_DOUBLE] % 1000) - 500);
mpq_set_d (q, d);
- /* Check that n/d = a * 2^exp, or
- d*a 2^{exp} = n */
- mpz_mul (t, a, mpq_denref (q));
- if (exp > 0)
- mpz_mul_2exp (t, t, exp);
- else
- {
- if (!mpz_divisible_2exp_p (t, -exp))
- goto fail;
- mpz_div_2exp (t, t, -exp);
- }
- if (mpz_cmp (t, mpq_numref (q)) != 0)
+ nd = mpz_get_d (mpq_numref (q));
+ dd = mpz_get_d (mpq_denref (q));
+ d2 = nd / dd;
+ if (d != d2)
{
- fail:
printf ("ERROR (check_random test %d): bad mpq_set_d results\n", test);
printf ("%.16g\n", d);
- gmp_printf ("%Qd\n", q);
+ printf ("%.16g\n", d2);
abort ();
}
}
mpq_clear (q);
- mpz_clear (t);
- mpz_clear (a);
}
void