summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-11-19 12:39:10 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-11-19 12:39:10 +0000
commit38c77249c6671159c0c7e40a73f1f5a3bc76dc8e (patch)
treefd12f35cf4b230dfcccf5eaf65a216f3ba0cdca7 /tests
parent68d7536264604dfa93c6540d11fd292e6e14e3ff (diff)
downloadmpfr-38c77249c6671159c0c7e40a73f1f5a3bc76dc8e.tar.gz
Improve coverage tests.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@3107 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r--tests/tabs.c2
-rw-r--r--tests/tcmp.c2
-rw-r--r--tests/tcmp_ui.c8
-rw-r--r--tests/texceptions.c44
-rw-r--r--tests/tget_z.c21
-rw-r--r--tests/tpow.c9
-rw-r--r--tests/tset.c2
-rw-r--r--tests/tset_sj.c3
-rw-r--r--tests/tsgn.c6
-rw-r--r--tests/tsqr.c34
10 files changed, 121 insertions, 10 deletions
diff --git a/tests/tabs.c b/tests/tabs.c
index ba65061b3..97cb83910 100644
--- a/tests/tabs.c
+++ b/tests/tabs.c
@@ -85,7 +85,7 @@ check_cmp(int argc, char *argv[])
mpfr_inits2(53, x, y, NULL);
mpfr_set_ui(x, 1, GMP_RNDN);
- mpfr_abs(x, x, GMP_RNDN);
+ (mpfr_abs) (x, x, GMP_RNDN);
if (mpfr_cmp_ui (x, 1))
{
printf ("Error in mpfr_abs(1.0)\n");
diff --git a/tests/tcmp.c b/tests/tcmp.c
index f40e9dbe1..1fa7e0948 100644
--- a/tests/tcmp.c
+++ b/tests/tcmp.c
@@ -41,7 +41,7 @@ main (void)
mpfr_set_prec (yy, 2);
mpfr_set_str_binary(xx, "-0.10E0");
mpfr_set_str_binary(yy, "-0.10E0");
- if (mpfr_cmp (xx, yy))
+ if ((mpfr_cmp) (xx, yy))
{
printf ("mpfr_cmp (xx, yy) returns non-zero for prec=2\n");
exit (1);
diff --git a/tests/tcmp_ui.c b/tests/tcmp_ui.c
index 819bf4649..197a2ac57 100644
--- a/tests/tcmp_ui.c
+++ b/tests/tcmp_ui.c
@@ -38,7 +38,7 @@ main (void)
/* tests for cmp_ui */
mpfr_set_ui (x, 3, GMP_RNDZ);
- if (mpfr_cmp_ui (x, i = 3) != 0)
+ if ((mpfr_cmp_ui) (x, i = 3) != 0)
{
printf ("Error in mpfr_cmp_ui(3.0, 3)\n");
exit (1);
@@ -60,6 +60,12 @@ main (void)
printf ("Error in mpfr_cmp_ui(0.0,0)\n");
exit (1);
}
+ mpfr_set_ui (x, 1, GMP_RNDZ);
+ if (mpfr_cmp_ui (x, i = 0) == 0)
+ {
+ printf ("Error in mpfr_cmp_ui(1.0,0)\n");
+ exit (1);
+ }
mpfr_set_ui (x, 0, GMP_RNDN);
mpfr_ui_div (x, 1, x, GMP_RNDU);
diff --git a/tests/texceptions.c b/tests/texceptions.c
index 1ff15158f..138253479 100644
--- a/tests/texceptions.c
+++ b/tests/texceptions.c
@@ -26,6 +26,20 @@ MA 02111-1307, USA. */
#define ERROR(s) do { printf(s); exit(1); } while(0)
+/* Test powerof2 */
+static void
+check_powerof2 (void)
+{
+ mpfr_t x;
+
+ mpfr_init (x);
+ mpfr_set_ui (x, 1, GMP_RNDN);
+ MPFR_ASSERTN (mpfr_powerof2_raw (x));
+ mpfr_set_ui (x, 3, GMP_RNDN);
+ MPFR_ASSERTN (!mpfr_powerof2_raw (x));
+ mpfr_clear (x);
+}
+
/* Test default rounding mode */
static void
check_default_rnd (void)
@@ -34,7 +48,7 @@ check_default_rnd (void)
for(r = 0 ; r < GMP_RND_MAX ; r++)
{
mpfr_set_default_rounding_mode (r);
- t = mpfr_get_default_rounding_mode();
+ t = (mpfr_get_default_rounding_mode) ();
if (r !=t)
ERROR("ERROR in setting / getting default rounding mode (1)\n");
}
@@ -63,12 +77,37 @@ check_emin_emax (void)
ERROR("get_emax FAILED!");
if ((mpfr_set_emax)(MPFR_EMAX_MAX+1) == 0)
ERROR("set_emax failed! (2)");
+
+ if ((mpfr_get_emin_min) () != MPFR_EMIN_MIN)
+ ERROR ("get_emin_min");
+ if ((mpfr_get_emin_max) () != MPFR_EMIN_MAX)
+ ERROR ("get_emin_max");
+ if ((mpfr_get_emax_min) () != MPFR_EMAX_MIN)
+ ERROR ("get_emax_min");
+ if ((mpfr_get_emax_max) () != MPFR_EMAX_MAX)
+ ERROR ("get_emax_max");
+}
+
+static void
+check_set_get_prec (void)
+{
+ mpfr_t x;
+
+ mpfr_init2 (x, 17);
+ if (mpfr_get_prec (x) != 17 || (mpfr_get_prec)(x) != 17)
+ ERROR ("mpfr_get_prec");
+ mpfr_clear (x);
}
static void
mpfr_set_double_range (void)
{
+ mpfr_set_default_prec (54);
+ if (mpfr_get_default_prec () != 54)
+ ERROR ("get_default_prec failed (1)");
mpfr_set_default_prec (53);
+ if ((mpfr_get_default_prec) () != 53)
+ ERROR ("get_default_prec failed (2)");
/* in double precision format, the unbiased exponent is between 0 and
2047, where 0 is used for subnormal numbers, and 2047 for special
@@ -311,7 +350,8 @@ main (int argc, char *argv[])
check_emin_emax();
check_flags();
-
+ check_set_get_prec ();
+ check_powerof2 ();
tests_end_mpfr ();
return 0;
}
diff --git a/tests/tget_z.c b/tests/tget_z.c
index 7894b4480..52c59e239 100644
--- a/tests/tget_z.c
+++ b/tests/tget_z.c
@@ -25,6 +25,26 @@ MA 02111-1307, USA. */
#include "mpfr-test.h"
static void
+check_diff (void)
+{
+ mpfr_t x;
+ mpz_t z;
+
+ mpz_init (z);
+ mpfr_init2 (x, 2);
+
+ mpfr_set_ui (x, 2047, GMP_RNDU);
+ mpz_set_fr (z, x, GMP_RNDN);
+ if (mpz_cmp_ui (z, 2048) != 0)
+ {
+ printf ("get_z RU 2048 failed\n");
+ exit (1);
+ }
+ mpfr_clear (x);
+ mpz_clear (z);
+}
+
+static void
check_one (mpz_ptr z)
{
int sh, neg;
@@ -97,6 +117,7 @@ main (void)
tests_start_mpfr ();
check ();
+ check_diff ();
tests_end_mpfr ();
return 0;
diff --git a/tests/tpow.c b/tests/tpow.c
index 69f9b5aa8..d31f90351 100644
--- a/tests/tpow.c
+++ b/tests/tpow.c
@@ -75,6 +75,15 @@ check_pow_ui (void)
exit (1);
}
+ mpfr_set_str_binary (a, "1E-10");
+ res = mpfr_pow_ui (a, a, -mpfr_get_emin (), GMP_RNDZ);
+ if (!MPFR_IS_ZERO (a))
+ {
+ printf ("Error for (1e-10)^MPFR_EMAX_MAX\n");
+ mpfr_dump (a);
+ exit (1);
+ }
+
/* Check overflow */
mpfr_set_str_binary (a, "1E10");
res = mpfr_pow_ui (a, a, ULONG_MAX, GMP_RNDN);
diff --git a/tests/tset.c b/tests/tset.c
index 4f67b035e..6358c4194 100644
--- a/tests/tset.c
+++ b/tests/tset.c
@@ -59,7 +59,7 @@ main (void)
inexact = mpfr_init_set_d (u, 1.0, GMP_RNDN);
mpfr_set_nan (x);
- mpfr_set (y, x, GMP_RNDN);
+ (mpfr_set) (y, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_nan_p (y));
mpfr_set_inf (x, 1);
diff --git a/tests/tset_sj.c b/tests/tset_sj.c
index c43dbd7c6..000f13f51 100644
--- a/tests/tset_sj.c
+++ b/tests/tset_sj.c
@@ -96,6 +96,9 @@ check_set_uj (mp_prec_t pmin, mp_prec_t pmax, int N)
if (inex1 != 0 || !mpfr_powerof2_raw (x)
|| MPFR_EXP (x) != (sizeof(uintmax_t)*CHAR_BIT+1) )
ERROR ("power of 2");
+ mpfr_set_uj (x, 0, GMP_RNDN);
+ if (!MPFR_IS_ZERO (x))
+ ERROR ("Setting 0");
mpfr_clears (x, y, NULL);
}
diff --git a/tests/tsgn.c b/tests/tsgn.c
index 2273ce775..ccbc4e136 100644
--- a/tests/tsgn.c
+++ b/tests/tsgn.c
@@ -33,21 +33,21 @@ check_special(void)
mpfr_init(x);
MPFR_SET_ZERO(x);
- if (mpfr_sgn(x) != 0)
+ if ((mpfr_sgn) (x) != 0)
{
printf("Sgn error for 0.\n");
ret = 1;
}
MPFR_SET_INF(x);
MPFR_SET_POS(x);
- if (mpfr_sgn(x) != 1)
+ if ((mpfr_sgn) (x) != 1)
{
printf("Sgn error for +Inf.\n");
ret = 1;
}
MPFR_SET_INF(x);
MPFR_SET_NEG(x);
- if (mpfr_sgn(x) != -1)
+ if ((mpfr_sgn) (x) != -1)
{
printf("Sgn error for -Inf.\n");
ret = 1;
diff --git a/tests/tsqr.c b/tests/tsqr.c
index 037844503..6d8a84df0 100644
--- a/tests/tsqr.c
+++ b/tests/tsqr.c
@@ -89,5 +89,37 @@ void check_random(mpfr_prec_t p)
void check_special(void)
{
-
+ mpfr_t x, y;
+ mp_exp_t emin;
+
+ mpfr_init (x);
+ mpfr_init (y);
+
+ mpfr_set_nan (x);
+ mpfr_sqr (y, x, GMP_RNDN);
+ MPFR_ASSERTN (mpfr_nan_p (y));
+
+ mpfr_set_inf (x, 1);
+ mpfr_sqr (y, x, GMP_RNDN);
+ MPFR_ASSERTN (mpfr_inf_p (y) && mpfr_sgn (y) > 0);
+
+ mpfr_set_inf (x, -1);
+ mpfr_sqr (y, x, GMP_RNDN);
+ MPFR_ASSERTN (mpfr_inf_p (y) && mpfr_sgn (y) > 0);
+
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_sqr (y, x, GMP_RNDN);
+ MPFR_ASSERTN (mpfr_zero_p (y));
+
+ emin = mpfr_get_emin ();
+ mpfr_set_emin (0);
+ mpfr_set_ui (x, 1, GMP_RNDN);
+ mpfr_div_2ui (x, x, 1, GMP_RNDN);
+ MPFR_ASSERTN (!mpfr_zero_p (x));
+ mpfr_sqr (y, x, GMP_RNDN);
+ MPFR_ASSERTN (mpfr_zero_p (y));
+ mpfr_set_emin (emin);
+
+ mpfr_clear (y);
+ mpfr_clear (x);
}