summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorthevenyp <thevenyp@280ebfd0-de03-0410-8827-d642c229c3f4>2007-11-20 11:21:10 +0000
committerthevenyp <thevenyp@280ebfd0-de03-0410-8827-d642c229c3f4>2007-11-20 11:21:10 +0000
commit8464b464ea878d1fcda732579cf8b1b331baf541 (patch)
treeb5e27e5d826c217e7e2a14899bf2ce9a4a14cb26 /tests
parent22a27b5f35282f2479e12a4e719ebc419599b9d7 (diff)
downloadmpfr-8464b464ea878d1fcda732579cf8b1b331baf541.tar.gz
use of RANDS instead of __gmp_rands
tset_f.c add checking with random values git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@4956 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r--tests/tpow_z.c11
-rw-r--r--tests/trandom.c5
-rw-r--r--tests/tset_f.c39
3 files changed, 35 insertions, 20 deletions
diff --git a/tests/tpow_z.c b/tests/tpow_z.c
index de4c1a9aa..94c575e49 100644
--- a/tests/tpow_z.c
+++ b/tests/tpow_z.c
@@ -25,15 +25,6 @@ MA 02110-1301, USA. */
#include <time.h>
#include <math.h>
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h> /* for struct timeval */
-# include <time.h>
-#elif HAVE_SYS_TIME_H
-# include <sys/time.h>
-#else
-# include <time.h>
-#endif
-
#include "mpfr-test.h"
#define ERROR(str) do { printf("Error for "str"\n"); exit (1); } while (0)
@@ -166,7 +157,7 @@ check_integer (mp_prec_t begin, mp_prec_t end, unsigned long max)
mpfr_set_prec (y2, p);
for (i = 0 ; i < max ; i++)
{
- mpz_urandomb (z, __gmp_rands, GMP_NUMB_BITS);
+ mpz_urandomb (z, RANDS, GMP_NUMB_BITS);
if ((i & 1) != 0)
mpz_neg (z, z);
mpfr_random (x);
diff --git a/tests/trandom.c b/tests/trandom.c
index 364f6648d..798d2ff1f 100644
--- a/tests/trandom.c
+++ b/tests/trandom.c
@@ -22,7 +22,6 @@ MA 02110-1301, USA. */
#include <stdio.h>
#include <stdlib.h>
-#include <time.h>
#include "mpfr-test.h"
@@ -196,7 +195,7 @@ test_urandomb (long nbtests, mp_prec_t prec, int verbose)
for (k = 0; k < nbtests; k++)
{
- mpfr_urandomb (x, __gmp_rands);
+ mpfr_urandomb (x, RANDS);
/* check that lower bits are zero */
if (MPFR_MANT(x)[0] & MPFR_LIMB_MASK(sh))
{
@@ -212,7 +211,7 @@ test_urandomb (long nbtests, mp_prec_t prec, int verbose)
emin = mpfr_get_emin ();
set_emin (1); /* the generated number in [0,1[ is not in the exponent
range, except if it is zero */
- k = mpfr_urandomb (x, __gmp_rands);
+ k = mpfr_urandomb (x, RANDS);
if (MPFR_IS_ZERO(x) == 0 && (k == 0 || mpfr_nan_p (x) == 0))
{
printf ("Error in mpfr_urandomb, expected NaN, got ");
diff --git a/tests/tset_f.c b/tests/tset_f.c
index 49e774ebd..441dda4a0 100644
--- a/tests/tset_f.c
+++ b/tests/tset_f.c
@@ -22,7 +22,6 @@ MA 02110-1301, USA. */
#include <stdio.h>
#include <stdlib.h>
-#include <time.h>
#include <limits.h> /* for ULONG_MAX */
#include "mpfr-test.h"
@@ -48,7 +47,7 @@ main (void)
mpfr_set_prec (x, 100);
mpfr_set_f (x, y, GMP_RNDN);
- mpf_urandomb (y, __gmp_rands, 10 * GMP_NUMB_BITS);
+ mpf_urandomb (y, RANDS, 10 * GMP_NUMB_BITS);
mpfr_set_f (x, y, (mp_rnd_t) RND_RAND());
/* bug found by Jean-Pierre Merlet */
@@ -56,8 +55,8 @@ main (void)
mpf_set_prec (y, 256);
mpfr_init2 (u, 256);
mpfr_set_str (u,
- "7.f10872b020c49ba5e353f7ced916872b020c49ba5e353f7ced916872b020c498@2",
- 16, GMP_RNDN);
+ "7.f10872b020c49ba5e353f7ced916872b020c49ba5e353f7ced916872b020c498@2",
+ 16, GMP_RNDN);
mpf_set_str (y, "2033033E-3", 10); /* avoid 2033.033 which is
locale-sensitive */
mpfr_set_f (x, y, GMP_RNDN);
@@ -89,13 +88,39 @@ main (void)
}
MPFR_ASSERTN(mpfr_cmp_ui_2exp (x, 1, 901) == 0);
- for (k = 1; k <= 100000; k++)
+ /* random values */
+ for (k = 1; k <= 1000; k++)
{
pr = 2 + (randlimb () & 255);
mpf_set_prec (z, pr);
- mpf_urandomb (z, __gmp_rands, z->_mp_prec);
+ mpf_urandomb (z, RANDS, z->_mp_prec);
+ mpfr_set_prec (u, ((pr / BITS_PER_MP_LIMB + 1) * BITS_PER_MP_LIMB));
+ mpfr_set_f (u, z, GMP_RNDN);
+ if (mpfr_cmp_f (u , z) != 0)
+ {
+ printf ("Error in mpfr_set_f:\n");
+ printf ("mpf (precision=%lu)=", pr);
+ mpf_out_str (stdout, 16, 0, z);
+ printf ("\nmpfr(precision=%lu)=",
+ ((pr / BITS_PER_MP_LIMB + 1) * BITS_PER_MP_LIMB));
+ mpfr_out_str (stdout, 16, 0, u, GMP_RNDN);
+ putchar ('\n');
+ exit (1);
+ }
mpfr_set_prec (x, pr);
- mpfr_set_f (x, z, (mp_rnd_t) 0);
+ mpfr_set_f (x, z, GMP_RNDN);
+ mpfr_sub (u, u, x, GMP_RNDN);
+ mpfr_abs (u, u, GMP_RNDN);
+ if (mpfr_cmp_ui_2exp (u, 1, -pr - 1) > 0)
+ {
+ printf ("Error in mpfr_set_f: precision=%lu\n", pr);
+ printf ("mpf =");
+ mpf_out_str (stdout, 16, 0, z);
+ printf ("\nmpfr=");
+ mpfr_out_str (stdout, 16, 0, x, GMP_RNDN);
+ putchar ('\n');
+ exit (1);
+ }
}
/* Check for +0 */