summaryrefslogtreecommitdiff
path: root/tests/tconst_log2.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2016-02-02 15:50:04 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2016-02-02 15:50:04 +0000
commit690e740380eaa2b062fff6d0cea11936076973a2 (patch)
treed2c12fba5075c0a3d09ea8238a69e5c38ee17e2c /tests/tconst_log2.c
parentc627b00303451c966248b114822eedc52e75c9fc (diff)
downloadmpfr-690e740380eaa2b062fff6d0cea11936076973a2.tar.gz
refactor the exhaustive search code in mpfr_const_log2
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9912 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tconst_log2.c')
-rw-r--r--tests/tconst_log2.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/tests/tconst_log2.c b/tests/tconst_log2.c
index fe97f3392..3136636c8 100644
--- a/tests/tconst_log2.c
+++ b/tests/tconst_log2.c
@@ -29,7 +29,7 @@ check (mpfr_prec_t p0, mpfr_prec_t p1)
{
mpfr_t x, y, z;
mpfr_rnd_t rnd;
- int dif;
+ int inex, inex_ref;
mpfr_init (x);
mpfr_init (y);
@@ -37,22 +37,27 @@ check (mpfr_prec_t p0, mpfr_prec_t p1)
mpfr_const_log2 (z, MPFR_RNDN);
mpfr_clear_cache (__gmpfr_cache_const_log2);
- for (; p0<=p1; p0++)
+ for (; p0 <= p1; p0++)
{
mpfr_set_prec (x, p0);
mpfr_set_prec (y, p0);
+ for (rnd = 0; rnd < MPFR_RND_MAX; rnd++)
{
- rnd = RND_RAND ();
- mpfr_const_log2 (x, rnd);
- mpfr_set (y, z, rnd);
- if ((dif = mpfr_cmp (x, y))
- && mpfr_can_round (z, mpfr_get_prec(z), MPFR_RNDN,
- rnd, p0))
+ inex = mpfr_const_log2 (x, rnd);
+ inex_ref = mpfr_set (y, z, rnd);
+ if (mpfr_can_round (z, mpfr_get_prec (z), MPFR_RNDN, rnd, p0) == 0)
{
- printf ("mpfr_const_log2 fails for prec=%u, rnd=%s Diff=%d\n",
- (unsigned int) p0, mpfr_print_rnd_mode (rnd), dif);
+ printf ("increase guard precision in check()\n");
+ exit (1);
+ }
+ if (mpfr_cmp (x, y) || inex != inex_ref)
+ {
+ printf ("mpfr_const_log2 fails for prec=%u, rnd=%s\n",
+ (unsigned int) p0, mpfr_print_rnd_mode (rnd));
printf ("expected "), mpfr_dump (y);
printf ("got "), mpfr_dump (x);
+ printf ("expected inex = %d\n", inex_ref);
+ printf ("got inex = %d\n", inex);
exit (1);
}
}
@@ -159,7 +164,9 @@ main (int argc, char *argv[])
mpfr_init (x);
- check (2, 1000);
+ /* increase the 2nd argument to say 300000 to perform the exhaustive search
+ in src/const_log2.c */
+ check (MPFR_PREC_MIN, 1000);
/* check precision of 2 bits */
mpfr_set_prec (x, 2);