summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-05-29 10:19:18 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-05-29 10:19:18 +0000
commit1dda6f3270c62d40dc6faff877c08ab935d2a138 (patch)
tree886bbee077f0697a892aa23a7814f1c6f087d4ce /tests
parentb8b853306f903fe8e2806a3ed29fb7fa53b31f34 (diff)
downloadmpfr-1dda6f3270c62d40dc6faff877c08ab935d2a138.tar.gz
[tests] Added always_scale argument (boolean) to tests_default_random()
so that when it is true, scaling is always performed on random numbers generated by mpfr_urandomb(), instead of preferring numbers of the order of magnitude of 1 for half outputs. This will be useful for mpfr_rint_* tests. For tgeneric.c, the value of this argument is controlled by a new macro TEST_RANDOM_ALWAYS_SCALE (0 by default, which corresponds to the current behavior). For the other tests that call tests_default_random(), the argument is set to 0, so that the behavior remains the same. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9471 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r--tests/mpfr-test.h3
-rw-r--r--tests/tests.c7
-rw-r--r--tests/tfprintf.c2
-rw-r--r--tests/tgeneric.c11
-rw-r--r--tests/tprintf.c2
-rw-r--r--tests/tsin_cos.c2
-rw-r--r--tests/tsum.c3
7 files changed, 20 insertions, 10 deletions
diff --git a/tests/mpfr-test.h b/tests/mpfr-test.h
index 102911019..6e39b7a28 100644
--- a/tests/mpfr-test.h
+++ b/tests/mpfr-test.h
@@ -97,7 +97,8 @@ void ld_trace _MPFR_PROTO ((const char *, long double));
FILE *src_fopen _MPFR_PROTO ((const char *, const char *));
void set_emin _MPFR_PROTO ((mpfr_exp_t));
void set_emax _MPFR_PROTO ((mpfr_exp_t));
-void tests_default_random _MPFR_PROTO ((mpfr_ptr, int, mpfr_exp_t, mpfr_exp_t));
+void tests_default_random _MPFR_PROTO ((mpfr_ptr, int, mpfr_exp_t, mpfr_exp_t,
+ int));
void data_check _MPFR_PROTO ((const char *, int (*) (FLIST), const char *));
void bad_cases _MPFR_PROTO ((int (*)(FLIST), int (*)(FLIST),
const char *, int, mpfr_exp_t, mpfr_exp_t,
diff --git a/tests/tests.c b/tests/tests.c
index f869fe476..18e7ad0d1 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -589,7 +589,8 @@ set_emax (mpfr_exp_t exponent)
If pos=0, all generated numbers are positive.
*/
void
-tests_default_random (mpfr_ptr x, int pos, mpfr_exp_t emin, mpfr_exp_t emax)
+tests_default_random (mpfr_ptr x, int pos, mpfr_exp_t emin, mpfr_exp_t emax,
+ int always_scale)
{
MPFR_ASSERTN (emin <= emax);
MPFR_ASSERTN (emin >= MPFR_EMIN_MIN);
@@ -600,7 +601,7 @@ tests_default_random (mpfr_ptr x, int pos, mpfr_exp_t emin, mpfr_exp_t emax)
exponent range (well, this is a bit ugly...). */
mpfr_urandomb (x, RANDS);
- if (MPFR_IS_PURE_FP (x) && (emin >= 1 || (randlimb () & 1)))
+ if (MPFR_IS_PURE_FP (x) && (emin >= 1 || always_scale || (randlimb () & 1)))
{
mpfr_exp_t e;
e = emin + (mpfr_exp_t) (randlimb () % (emax - emin + 1));
@@ -922,7 +923,7 @@ bad_cases (int (*fct)(FLIST), int (*inv)(FLIST), const char *name,
printf ("bad_cases: i = %d\n", i);
py = pymin + (randlimb () % (pymax - pymin + 1));
mpfr_set_prec (y, py);
- tests_default_random (y, pos, emin, emax);
+ tests_default_random (y, pos, emin, emax, 0);
if (dbg)
{
printf ("bad_cases: yprec =%4ld, y = ", (long) py);
diff --git a/tests/tfprintf.c b/tests/tfprintf.c
index 26624d609..41d067f15 100644
--- a/tests/tfprintf.c
+++ b/tests/tfprintf.c
@@ -311,7 +311,7 @@ check_random (FILE *fout, int nb_tests)
char fmt[FMT_SIZE]; /* at most something like "%-+ #0'.*R*f" */
char *ptr = fmt;
- tests_default_random (x, 256, MPFR_EMIN_MIN, MPFR_EMAX_MAX);
+ tests_default_random (x, 256, MPFR_EMIN_MIN, MPFR_EMAX_MAX, 0);
rnd = RND_RAND ();
spec = (int) (randlimb () % 5);
diff --git a/tests/tgeneric.c b/tests/tgeneric.c
index da2f33dd2..31f9f247d 100644
--- a/tests/tgeneric.c
+++ b/tests/tgeneric.c
@@ -43,6 +43,10 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#define TEST_RANDOM_EMAX 255
#endif
+#ifndef TEST_RANDOM_ALWAYS_SCALE
+#define TEST_RANDOM_ALWAYS_SCALE 0
+#endif
+
/* If the MPFR_SUSPICIOUS_OVERFLOW test fails but this is not a bug,
then define TGENERIC_SO_TEST with an adequate test (possibly 0) to
omit this particular case. */
@@ -182,10 +186,12 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax)
#endif
#else
tests_default_random (x, TEST_RANDOM_POS,
- TEST_RANDOM_EMIN, TEST_RANDOM_EMAX);
+ TEST_RANDOM_EMIN, TEST_RANDOM_EMAX,
+ TEST_RANDOM_ALWAYS_SCALE);
#if defined(TWO_ARGS) || defined(DOUBLE_ARG1) || defined(DOUBLE_ARG2)
tests_default_random (u, TEST_RANDOM_POS2,
- TEST_RANDOM_EMIN, TEST_RANDOM_EMAX);
+ TEST_RANDOM_EMIN, TEST_RANDOM_EMAX,
+ TEST_RANDOM_ALWAYS_SCALE);
#endif
#endif
}
@@ -497,6 +503,7 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax)
#undef TEST_RANDOM_POS2
#undef TEST_RANDOM_EMIN
#undef TEST_RANDOM_EMAX
+#undef TEST_RANDOM_ALWAYS_SCALE
#undef RAND_FUNCTION
#undef TWO_ARGS
#undef TWO_ARGS_UI
diff --git a/tests/tprintf.c b/tests/tprintf.c
index 157e7c5ab..7c685264b 100644
--- a/tests/tprintf.c
+++ b/tests/tprintf.c
@@ -338,7 +338,7 @@ check_random (int nb_tests)
char fmt[FMT_SIZE]; /* at most something like "%-+ #0'.*R*f" */
char *ptr = fmt;
- tests_default_random (x, 256, MPFR_EMIN_MIN, MPFR_EMAX_MAX);
+ tests_default_random (x, 256, MPFR_EMIN_MIN, MPFR_EMAX_MAX, 0);
rnd = (mpfr_rnd_t) RND_RAND ();
spec = (int) (randlimb () % 5);
diff --git a/tests/tsin_cos.c b/tests/tsin_cos.c
index c3fcb5d83..789c40da6 100644
--- a/tests/tsin_cos.c
+++ b/tests/tsin_cos.c
@@ -585,7 +585,7 @@ consistency (void)
}
else
{
- tests_default_random (x, 256, -5, 50);
+ tests_default_random (x, 256, -5, 50, 0);
rnd = RND_RAND ();
flags_before = (randlimb () & 1) ?
(unsigned int) (MPFR_FLAGS_ALL ^ MPFR_FLAGS_ERANGE) :
diff --git a/tests/tsum.c b/tests/tsum.c
index 28f2cf984..ea94225b4 100644
--- a/tests/tsum.c
+++ b/tests/tsum.c
@@ -828,7 +828,8 @@ cancel (void)
e = (i & 1) ? 0 : mpfr_get_emin ();
tests_default_random (x[n], 256, e,
- ((i & 2) ? e + 2000 : mpfr_get_emax ()));
+ ((i & 2) ? e + 2000 : mpfr_get_emax ()),
+ 0);
}
else
{