summaryrefslogtreecommitdiff
path: root/tests/tgrandom.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2012-06-27 08:21:10 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2012-06-27 08:21:10 +0000
commited10f6711ab7c4c4502960a194e7a68e30e07a52 (patch)
tree85492727b814f626af1dd9739bc8bcbf72943953 /tests/tgrandom.c
parent125c67db81d461144200bab123a5ce8723a1677c (diff)
downloadmpfr-ed10f6711ab7c4c4502960a194e7a68e30e07a52.tar.gz
[tests/tgrandom.c] Improved a test and added a new one for
mpfr_grandom(x, NULL, ...). git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@8280 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tgrandom.c')
-rw-r--r--tests/tgrandom.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/tests/tgrandom.c b/tests/tgrandom.c
index 7c65c9984..6c7c4355c 100644
--- a/tests/tgrandom.c
+++ b/tests/tgrandom.c
@@ -23,12 +23,37 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#include "mpfr-test.h"
static void
+test_special (mpfr_prec_t p)
+{
+ mpfr_t x;
+ int inexact;
+
+ mpfr_init2 (x, p);
+
+ inexact = mpfr_grandom (x, NULL, RANDS, GMP_RNDN);
+ if ((inexact & 3) == 0)
+ {
+ printf ("Error: mpfr_grandom() returns a zero ternary value.\n");
+ exit (1);
+ }
+ if ((inexact & (3 << 2)) != 0)
+ {
+ printf ("Error: the second ternary value of mpfr_grandom(x, NULL, ...)"
+ " must be 0.\n");
+ exit (1);
+ }
+
+ mpfr_clear(x);
+}
+
+
+static void
test_grandom (long nbtests, mpfr_prec_t prec, mpfr_rnd_t rnd,
int verbose)
{
mpfr_t *t;
mpfr_t av, va, tmp;
- int i, inex, itmp;
+ int i, inexact;
nbtests = (nbtests & 1) ? (nbtests + 1) : nbtests;
t = (mpfr_t *) malloc (nbtests * sizeof (mpfr_t));
@@ -41,18 +66,15 @@ test_grandom (long nbtests, mpfr_prec_t prec, mpfr_rnd_t rnd,
for (i = 0; i < nbtests; ++i)
mpfr_init2 (t[i], prec);
- inex = 1;
for (i = 0; i < nbtests; i += 2)
{
- itmp = mpfr_grandom (t[i], t[i + 1], RANDS, MPFR_RNDN);
- inex = ((itmp & 3) != 0) && ((itmp & 12) != 0) && inex;
- }
-
- if (inex == 0)
- {
- /* one call in the loop pretended to return an exact number! */
- printf ("Error: mpfr_urandom_gaussian() returns a zero ternary value.\n");
- exit (1);
+ inexact = mpfr_grandom (t[i], t[i + 1], RANDS, MPFR_RNDN);
+ if ((inexact & 3) == 0 || (inexact & (3 << 2)) == 0)
+ {
+ /* one call in the loop pretended to return an exact number! */
+ printf ("Error: mpfr_grandom() returns a zero ternary value.\n");
+ exit (1);
+ }
}
#ifdef HAVE_STDARG
@@ -107,6 +129,8 @@ main (int argc, char *argv[])
}
test_grandom (nbtests, 420, MPFR_RNDN, verbose);
+ test_special (2);
+ test_special (42000);
tests_end_mpfr ();
return 0;