summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-14 11:11:31 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-14 11:11:31 +0000
commitf095a6c8a44a63379841097ddfbf4682e56e4036 (patch)
treeff27c1422f6c4e9e704d35ffc9953571a796f11c /tests
parentaedeae287d6c8de47317f93227626653a622d3ee (diff)
downloadmpfr-f095a6c8a44a63379841097ddfbf4682e56e4036.tar.gz
improved coverage test
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2713 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/inp_str.data3
-rw-r--r--tests/mpf_compat.h11
-rw-r--r--tests/thypot.c25
-rw-r--r--tests/tinp_str.c66
-rw-r--r--tests/tlog.c5
-rw-r--r--tests/tlog10.c30
-rw-r--r--tests/tlog1p.c41
-rw-r--r--tests/tlog2.c42
-rw-r--r--tests/tmul.c23
-rw-r--r--tests/tmul_ui.c18
-rw-r--r--tests/tnext.c22
-rw-r--r--tests/tout_str.c34
-rw-r--r--tests/tpow.c86
-rw-r--r--tests/trandom.c4
-rw-r--r--tests/trint.c92
-rw-r--r--tests/tround_prec.c39
-rw-r--r--tests/tset.c33
18 files changed, 557 insertions, 21 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 12fadf1ba..0214ac889 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,8 +1,8 @@
AUTOMAKE_OPTIONS = gnu
-check_PROGRAMS = tversion tinits tsgn tcheck tisnan texceptions tset tabs tset_d tset_f tset_q tset_si tset_str tset_z tset_ld tadd tsub tmul tdiv tcmp tcmp2 tcmpabs tcan_round tround_prec tswap reuse tsqrt tnext tcomparisons teq tadd_ui tsub_ui tcmp_ui tdiv_ui tmul_ui tsqrt_ui tui_div tui_sub tcmp_d tmul_2exp tfma tfrac tget_str tout_str tget_d tget_d_2exp tconst_log2 tconst_pi tconst_euler trandom ttrunc trint texp texp2 texpm1 tlog tlog2 tlog10 tlog1p tpow tui_pow tpow3 tcosh tsinh ttanh tacosh tasinh tatanh thyperbolic tasin tacos tcos tatan tsin ttan tsin_cos tagm thypot tfactorial tgamma terf tcbrt mpf_compat mpfr_compat tzeta tsub1sp tadd1sp tgmpop tsum tdim tminmax tcopysign toutimpl tfits
+check_PROGRAMS = tversion tinits tsgn tcheck tisnan texceptions tset tabs tset_d tset_f tset_q tset_si tset_str tset_z tset_ld tadd tsub tmul tdiv tcmp tcmp2 tcmpabs tcan_round tround_prec tswap reuse tsqrt tnext tcomparisons teq tadd_ui tsub_ui tcmp_ui tdiv_ui tmul_ui tsqrt_ui tui_div tui_sub tcmp_d tmul_2exp tfma tfrac tget_str tout_str tget_d tget_d_2exp tconst_log2 tconst_pi tconst_euler trandom ttrunc trint texp texp2 texpm1 tlog tlog2 tlog10 tlog1p tpow tui_pow tpow3 tcosh tsinh ttanh tacosh tasinh tatanh thyperbolic tasin tacos tcos tatan tsin ttan tsin_cos tagm thypot tfactorial tgamma terf tcbrt mpf_compat mpfr_compat tzeta tsub1sp tadd1sp tgmpop tsum tdim tminmax tcopysign toutimpl tfits tinp_str
-EXTRA_DIST = tgeneric.c mpf_compat.h
+EXTRA_DIST = tgeneric.c mpf_compat.h inp_str.data
LDADD = libfrtests.a $(MPFR_LIBM) $(top_builddir)/libmpfr.a @LDADD@
INCLUDES = -I$(top_srcdir) @INCLUDES@
diff --git a/tests/inp_str.data b/tests/inp_str.data
new file mode 100644
index 000000000..c8148a818
--- /dev/null
+++ b/tests/inp_str.data
@@ -0,0 +1,3 @@
+3.1415E4
+3.14160000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E4
+this_is_an_invalid_float
diff --git a/tests/mpf_compat.h b/tests/mpf_compat.h
index fbdd7ea5e..04f047efd 100644
--- a/tests/mpf_compat.h
+++ b/tests/mpf_compat.h
@@ -163,8 +163,15 @@ main ()
mpf_out_str (f, 10, 10, x);
fclose (f);
- f = fopen ("/dev/null", "r");
- mpf_inp_str (x, f, 10);
+ mpf_set_prec (x, 15);
+ mpf_set_prec (y, 15);
+ f = fopen ("inp_str.data", "r");
+ i = mpf_inp_str (x, f, 10);
+ if ((i == 0) || mpf_cmp_ui (x, 31415))
+ {
+ printf ("Error in reading 1st line from file inp_str.data\n");
+ exit (1);
+ }
fclose (f);
/* Miscellaneous Functions */
diff --git a/tests/thypot.c b/tests/thypot.c
index a93247331..fdb7eefab 100644
--- a/tests/thypot.c
+++ b/tests/thypot.c
@@ -29,6 +29,29 @@ MA 02111-1307, USA. */
#define TEST_FUNCTION mpfr_hypot
static void
+special (void)
+{
+ mpfr_t x, y, z;
+
+ mpfr_init (x);
+ mpfr_init (y);
+ mpfr_init (z);
+
+ mpfr_set_nan (x);
+ mpfr_hypot (z, x, y, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (z));
+
+ mpfr_set_inf (x, 1);
+ mpfr_set_inf (y, -1);
+ mpfr_hypot (z, x, y, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (z) && mpfr_sgn (z) > 0);
+
+ mpfr_clear (x);
+ mpfr_clear (y);
+ mpfr_clear (z);
+}
+
+static void
test_large (void)
{
mpfr_t x, y, z, t;
@@ -93,6 +116,8 @@ main (int argc, char *argv[])
tests_start_mpfr ();
+ special ();
+
mpfr_init (x1);
mpfr_init (x2);
mpfr_init (y);
diff --git a/tests/tinp_str.c b/tests/tinp_str.c
new file mode 100644
index 000000000..15a6db30a
--- /dev/null
+++ b/tests/tinp_str.c
@@ -0,0 +1,66 @@
+/* Test file for mpfr_inp_str.
+
+Copyright 2004 Free Software Foundation, Inc.
+
+This file is part of the MPFR Library.
+
+The MPFR Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The MPFR Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the MPFR Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "mpfr-test.h"
+
+int
+main (int argc, char *argv[])
+{
+ mpfr_t x;
+ FILE *f;
+ int i;
+
+ tests_start_mpfr ();
+
+ mpfr_init (x);
+
+ mpfr_set_prec (x, 15);
+ f = fopen ("inp_str.data", "r");
+ i = mpfr_inp_str (x, f, 10, GMP_RNDN);
+ if (i == 0 || mpfr_cmp_ui (x, 31415))
+ {
+ printf ("Error in reading 1st line from file inp_str.data\n");
+ exit (1);
+ }
+ getc (f);
+ i = mpfr_inp_str (x, f, 10, GMP_RNDN);
+ if ((i == 0) || mpfr_cmp_ui (x, 31416))
+ {
+ printf ("Error in reading 2nd line from file inp_str.data\n");
+ exit (1);
+ }
+ getc (f);
+ i = mpfr_inp_str (x, f, 10, GMP_RNDN);
+ if (i != 0)
+ {
+ printf ("Error in reading 3rd line from file inp_str.data\n");
+ exit (1);
+ }
+ fclose (f);
+
+ mpfr_clear (x);
+
+ tests_end_mpfr ();
+ return 0;
+}
diff --git a/tests/tlog.c b/tests/tlog.c
index d3f560d47..517c66c33 100644
--- a/tests/tlog.c
+++ b/tests/tlog.c
@@ -172,6 +172,11 @@ special (void)
mpfr_sqrt (x, x, GMP_RNDN);
mpfr_log (y, x, GMP_RNDN);
+ /* negative argument */
+ mpfr_set_si (x, -1, GMP_RNDN);
+ mpfr_log (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (y));
+
mpfr_clear (x);
mpfr_clear (y);
}
diff --git a/tests/tlog10.c b/tests/tlog10.c
index 792d4466b..e2aaa5ab0 100644
--- a/tests/tlog10.c
+++ b/tests/tlog10.c
@@ -38,12 +38,36 @@ main (int argc, char *argv[])
test_generic (2, 100, 20);
- /* check log10(10^n)=n */
mpfr_init2 (x, 53);
mpfr_init2 (y, 53);
- mpfr_set_ui (x, 1, GMP_RNDN);
- for (n=1; n<=15; n++)
+ /* check NaN */
+ mpfr_set_nan (x);
+ mpfr_log10 (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (y));
+
+ /* check Inf */
+ mpfr_set_inf (x, -1);
+ mpfr_log10 (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (y));
+
+ mpfr_set_inf (x, 1);
+ mpfr_log10 (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (y) && mpfr_sgn (y) > 0);
+
+ /* check negative argument */
+ mpfr_set_si (x, -1, GMP_RNDN);
+ mpfr_log10 (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (y));
+
+ /* check log10(1) = 0 */
+ mpfr_set_ui (x, 1, GMP_RNDN);
+ mpfr_log10 (y, x, GMP_RNDN);
+ MPFR_ASSERTN((mpfr_cmp_ui (y, 0) == 0) && (MPFR_IS_POS (y)));
+
+ /* check log10(10^n)=n */
+ mpfr_set_ui (x, 1, GMP_RNDN);
+ for (n = 1; n <= 15; n++)
{
mpfr_mul_ui (x, x, 10, GMP_RNDN); /* x = 10^n */
mpfr_log10 (y, x, GMP_RNDN);
diff --git a/tests/tlog1p.c b/tests/tlog1p.c
index 6ddf7a4f3..ffd1df02e 100644
--- a/tests/tlog1p.c
+++ b/tests/tlog1p.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_log1p.
-Copyright 2001, 2002, 2003 Free Software Foundation.
+Copyright 2001, 2002, 2003, 2004 Free Software Foundation.
Adapted from tsinh.c.
This file is part of the MPFR Library.
@@ -28,11 +28,50 @@ MA 02111-1307, USA. */
#define TEST_FUNCTION mpfr_log1p
#include "tgeneric.c"
+static void
+special (void)
+{
+ mpfr_t x;
+
+ mpfr_init (x);
+
+ mpfr_set_nan (x);
+ mpfr_log1p (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (x));
+
+ mpfr_set_inf (x, -1);
+ mpfr_log1p (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (x));
+
+ mpfr_set_inf (x, 1);
+ mpfr_log1p (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
+
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_log1p (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS (x));
+ mpfr_neg (x, x, GMP_RNDN);
+ mpfr_log1p (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_NEG (x));
+
+ mpfr_set_si (x, -1, GMP_RNDN);
+ mpfr_log1p (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0);
+
+ mpfr_set_si (x, -2, GMP_RNDN);
+ mpfr_log1p (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (x));
+
+ mpfr_clear (x);
+}
+
int
main (int argc, char *argv[])
{
tests_start_mpfr ();
+ special ();
+
test_generic (2, 100, 50);
tests_end_mpfr ();
diff --git a/tests/tlog2.c b/tests/tlog2.c
index 5f6be8d35..8ecf1a574 100644
--- a/tests/tlog2.c
+++ b/tests/tlog2.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_log2.
-Copyright 2001, 2002 Free Software Foundation.
+Copyright 2001, 2002, 2004 Free Software Foundation.
Adapted from tsinh.c.
This file is part of the MPFR Library.
@@ -28,11 +28,51 @@ MA 02111-1307, USA. */
#define TEST_FUNCTION mpfr_log2
#include "tgeneric.c"
+static void
+special (void)
+{
+ mpfr_t x;
+
+ mpfr_init (x);
+
+ mpfr_set_nan (x);
+ mpfr_log2 (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (x));
+
+ mpfr_set_inf (x, -1);
+ mpfr_log2 (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (x));
+
+ mpfr_set_inf (x, 1);
+ mpfr_log2 (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
+
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_log2 (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0);
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_neg (x, x, GMP_RNDN);
+ mpfr_log2 (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0);
+
+ mpfr_set_si (x, -1, GMP_RNDN);
+ mpfr_log2 (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (x));
+
+ mpfr_set_si (x, 1, GMP_RNDN);
+ mpfr_log2 (x, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x));
+
+ mpfr_clear (x);
+}
+
int
main (int argc, char *argv[])
{
tests_start_mpfr ();
+ special ();
+
test_generic (2, 100, 30);
tests_end_mpfr ();
diff --git a/tests/tmul.c b/tests/tmul.c
index 9cd2ce08c..e825effda 100644
--- a/tests/tmul.c
+++ b/tests/tmul.c
@@ -257,6 +257,7 @@ static void
check_max(void)
{
mpfr_t xx, yy, zz;
+ mp_exp_t emin;
mpfr_init2(xx, 4);
mpfr_init2(yy, 4);
@@ -297,6 +298,28 @@ check_max(void)
exit(1);
}
+ /* check underflow */
+ emin = mpfr_get_emin ();
+ mpfr_set_emin (0);
+ mpfr_set_str_binary (xx, "0.1E0");
+ mpfr_set_str_binary (yy, "0.1E0");
+ mpfr_mul (zz, xx, yy, GMP_RNDN);
+ /* exact result is 0.1E-1, which should round to 0 */
+ MPFR_ASSERTN(mpfr_cmp_ui (zz, 0) == 0 && MPFR_IS_POS(zz));
+ mpfr_set_emin (emin);
+
+ /* coverage test for mpfr_powerof2_raw */
+ emin = mpfr_get_emin ();
+ mpfr_set_emin (0);
+ mpfr_set_prec (xx, mp_bits_per_limb + 1);
+ mpfr_set_str_binary (xx, "0.1E0");
+ mpfr_nextabove (xx);
+ mpfr_set_str_binary (yy, "0.1E0");
+ mpfr_mul (zz, xx, yy, GMP_RNDN);
+ /* exact result is just above 0.1E-1, which should round to minfloat */
+ MPFR_ASSERTN(mpfr_cmp (zz, yy) == 0);
+ mpfr_set_emin (emin);
+
mpfr_clear(xx);
mpfr_clear(yy);
mpfr_clear(zz);
diff --git a/tests/tmul_ui.c b/tests/tmul_ui.c
index d6beda616..24eb44d41 100644
--- a/tests/tmul_ui.c
+++ b/tests/tmul_ui.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_mul_ui.
-Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation.
+Copyright 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library.
@@ -80,6 +80,7 @@ main (int argc, char *argv[])
mpfr_t x, y;
unsigned int xprec, yprec, i;
mp_prec_t p;
+ mp_exp_t emax;
tests_start_mpfr ();
@@ -130,6 +131,21 @@ main (int argc, char *argv[])
exit (1);
}
+ mpfr_set_inf (x, 1);
+ mpfr_mul_ui (x, x, 0, GMP_RNDU);
+ MPFR_ASSERTN(mpfr_nan_p (x));
+
+ mpfr_set_ui (x, 1, GMP_RNDU);
+ mpfr_mul_ui (x, x, 0, GMP_RNDU);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x));
+
+ emax = mpfr_get_emax ();
+ mpfr_set_emax (0);
+ mpfr_set_str_binary (x, "0.1E0");
+ mpfr_mul_ui (x, x, 2, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (x) && MPFR_IS_POS(x));
+ mpfr_set_emax (emax);
+
mpfr_set_str (x, /*1.0/3.0*/
"0.333333333333333333333333333333333", 10, GMP_RNDZ);
mpfr_mul_ui (x, x, 3, GMP_RNDU);
diff --git a/tests/tnext.c b/tests/tnext.c
index 6a00d6c34..619987b0c 100644
--- a/tests/tnext.c
+++ b/tests/tnext.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_nextabove, mpfr_nextbelow, mpfr_nexttoward.
-Copyright 2003 Free Software Foundation.
+Copyright 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library.
@@ -39,6 +39,26 @@ generic_abovebelow (void)
prec = (randlimb () % 300) + MPFR_PREC_MIN;
mpfr_inits2 (prec, x, y, z, (void *) 0);
mpfr_init2 (t, 3);
+
+ /* special tests (executed once is enough) */
+ if (i == 0)
+ {
+ mpfr_set_nan (x);
+ mpfr_nextabove (x);
+ MPFR_ASSERTN(mpfr_nan_p (x));
+ mpfr_nextbelow (x);
+ MPFR_ASSERTN(mpfr_nan_p (x));
+ mpfr_nexttoward (x, y);
+ MPFR_ASSERTN(mpfr_nan_p (x));
+ mpfr_set_ui (y, 1, GMP_RNDN);
+ mpfr_nexttoward (y, x);
+ MPFR_ASSERTN(mpfr_nan_p (y));
+ mpfr_set_ui (x, 1, GMP_RNDN);
+ mpfr_set_ui (y, 1, GMP_RNDN);
+ mpfr_nexttoward (x, y);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0);
+ }
+
do
mpfr_random (x);
while (mpfr_cmp_ui (x, 0) == 0);
diff --git a/tests/tout_str.c b/tests/tout_str.c
index 12d222339..9dd275558 100644
--- a/tests/tout_str.c
+++ b/tests/tout_str.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_out_str.
-Copyright 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -100,6 +100,30 @@ check_large (void)
mpfr_clear (x);
}
+static void
+special (void)
+{
+ mpfr_t x;
+
+ mpfr_init (x);
+
+ mpfr_set_nan (x);
+ mpfr_out_str (fout, 10, 0, x, GMP_RNDN);
+
+ mpfr_set_inf (x, 1);
+ mpfr_out_str (fout, 10, 0, x, GMP_RNDN);
+
+ mpfr_set_inf (x, -1);
+ mpfr_out_str (fout, 10, 0, x, GMP_RNDN);
+
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_out_str (fout, 10, 0, x, GMP_RNDN);
+ mpfr_neg (x, x, GMP_RNDN);
+ mpfr_out_str (fout, 10, 0, x, GMP_RNDN);
+
+ mpfr_clear (x);
+}
+
int
main (int argc, char *argv[])
{
@@ -108,16 +132,20 @@ main (int argc, char *argv[])
tests_start_mpfr ();
- check_large ();
/* with no argument: prints to /dev/null,
tout_str N: prints N tests to stdout */
- if (argc==1)
+ if (argc == 1)
fout = fopen ("/dev/null", "w");
else
{
fout = stdout;
N = atoi (argv[1]);
}
+
+ special ();
+
+ check_large ();
+
check (-1.37247529013405550000e+15, GMP_RNDN, 7);
check (-1.5674376729569697500e+15, GMP_RNDN, 19);
check (-5.71262771772792640000e-79, GMP_RNDU, 16);
diff --git a/tests/tpow.c b/tests/tpow.c
index 7ab0cba52..0d2f1a1e1 100644
--- a/tests/tpow.c
+++ b/tests/tpow.c
@@ -1,6 +1,6 @@
-/* Test file for mpfr_pow and mpfr_pow_ui.
+/* Test file for mpfr_pow, mpfr_pow_ui and mpfr_pow_si.
-Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -69,6 +69,46 @@ check_pow_ui (void)
}
static void
+check_pow_si (void)
+{
+ mpfr_t x;
+
+ mpfr_init (x);
+
+ mpfr_set_nan (x);
+ mpfr_pow_si (x, x, -1, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (x));
+
+ mpfr_set_inf (x, 1);
+ mpfr_pow_si (x, x, -1, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x));
+
+ mpfr_set_inf (x, -1);
+ mpfr_pow_si (x, x, -1, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_NEG(x));
+
+ mpfr_set_inf (x, -1);
+ mpfr_pow_si (x, x, -2, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x));
+
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_pow_si (x, x, -1, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
+
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_neg (x, x, GMP_RNDN);
+ mpfr_pow_si (x, x, -1, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0);
+
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_neg (x, x, GMP_RNDN);
+ mpfr_pow_si (x, x, -2, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
+
+ mpfr_clear (x);
+}
+
+static void
check_inexact (mp_prec_t p)
{
mpfr_t x, y, z, t;
@@ -216,6 +256,43 @@ special ()
exit (1);
}
+ mpfr_set_inf (x, 1);
+ mpfr_set_prec (y, 2);
+ mpfr_set_str_binary (y, "1E10");
+ mpfr_pow (z, x, y, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z));
+ mpfr_set_inf (x, -1);
+ mpfr_pow (z, x, y, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z));
+ mpfr_set_prec (y, 10);
+ mpfr_set_str_binary (y, "1.000000001E9");
+ mpfr_pow (z, x, y, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_NEG(z));
+ mpfr_set_str_binary (y, "1.000000001E8");
+ mpfr_pow (z, x, y, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (z));
+
+ mpfr_set_inf (x, -1);
+ mpfr_set_prec (y, 2 * mp_bits_per_limb);
+ mpfr_set_ui (y, 1, GMP_RNDN);
+ mpfr_mul_2exp (y, y, mp_bits_per_limb - 1, GMP_RNDN);
+ mpfr_pow (z, x, y, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z));
+ mpfr_nextabove (y);
+ mpfr_pow (z, x, y, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (z));
+ mpfr_nextbelow (y);
+ mpfr_div_2exp (y, y, 1, GMP_RNDN);
+ mpfr_nextabove (y);
+ mpfr_pow (z, x, y, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (z));
+
+ mpfr_set_si (x, -1, GMP_RNDN);
+ mpfr_set_prec (y, 2);
+ mpfr_set_str_binary (y, "1E10");
+ mpfr_pow (z, x, y, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (z, 1) == 0);
+
mpfr_clear (x);
mpfr_clear (y);
mpfr_clear (z);
@@ -254,7 +331,7 @@ particular_cases (void)
/* NaN +inf -inf +0 -0 +1 -1 +2 -2 +0.5 -0.5 */
/* NaN */ { 0, 0, 0, 128, 128, 0, 0, 0, 0, 0, 0 },
/* +inf */ { 0, 1, 2, 128, 128, 1, 2, 1, 2, 1, 2 },
- /* -inf */ { 0, 1, 2, 128, 128, -1, -2, 1, 2, 1, 2 },
+ /* -inf */ { 0, 1, 2, 128, 128, -1, -2, 1, 2, 0, 0 },
/* +0 */ { 0, 2, 1, 128, 128, 2, 1, 2, 1, 2, 1 },
/* -0 */ { 0, 2, 1, 128, 128, -2, -1, 2, 1, 2, 1 },
/* +1 */ {128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 },
@@ -277,6 +354,7 @@ particular_cases (void)
{
printf ("Error in mpfr_pow for particular case (%s)^(%s) (%d,%d):\n"
"got %d instead of %d\n", name[i], name[j], i,j,p, q[i][j]);
+ mpfr_dump (r);
error = 1;
}
}
@@ -363,6 +441,8 @@ main (void)
particular_cases ();
check_pow_ui ();
+
+ check_pow_si ();
for (p=2; p<100; p++)
check_inexact (p);
diff --git a/tests/trandom.c b/tests/trandom.c
index 19d80aa87..ebd235054 100644
--- a/tests/trandom.c
+++ b/tests/trandom.c
@@ -118,6 +118,10 @@ test_random2 (long nbtests, mp_prec_t prec, int verbose)
tab[(int)(size_tab * d)]++;
}
+ /* test size=0 */
+ mpfr_random2 (x, 0, 0);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x));
+
mpfr_clear (x);
if (!verbose)
{
diff --git a/tests/trint.c b/tests/trint.c
index a773f195c..a56db01a8 100644
--- a/tests/trint.c
+++ b/tests/trint.c
@@ -29,9 +29,96 @@ static void
special (void)
{
mpfr_t x, y;
+ mp_exp_t emax;
- mpfr_init2 (x, 6);
- mpfr_init2 (y, 3);
+ mpfr_init (x);
+ mpfr_init (y);
+
+ mpfr_set_nan (x);
+ mpfr_rint (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (y));
+
+ mpfr_set_inf (x, 1);
+ mpfr_rint (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (y) && mpfr_sgn (y) > 0);
+
+ mpfr_set_inf (x, -1);
+ mpfr_rint (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (y) && mpfr_sgn (y) < 0);
+
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_rint (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_POS(y));
+
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_neg (x, x, GMP_RNDN);
+ mpfr_rint (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_NEG(y));
+
+ /* coverage test */
+ mpfr_set_prec (x, 2);
+ mpfr_set_ui (x, 1, GMP_RNDN);
+ mpfr_mul_2exp (x, x, mp_bits_per_limb, GMP_RNDN);
+ mpfr_rint (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp (y, x) == 0);
+
+ /* another coverage test */
+ emax = mpfr_get_emax ();
+ mpfr_set_emax (1);
+ mpfr_set_prec (x, 3);
+ mpfr_set_str_binary (x, "1.11E0");
+ mpfr_set_prec (y, 2);
+ mpfr_rint (y, x, GMP_RNDU); /* x rounds to 1.0E1=0.1E2 which overflows */
+ MPFR_ASSERTN(mpfr_inf_p (y) && mpfr_sgn (y) > 0);
+ mpfr_set_emax (emax);
+
+ /* yet another */
+ mpfr_set_prec (x, 97);
+ mpfr_set_prec (y, 96);
+ mpfr_set_str_binary (x, "-0.1011111001101111000111011100011100000110110110110000000111010001000101001111101010101011010111100E97");
+ mpfr_rint (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp (y, x) == 0);
+
+ mpfr_set_prec (x, 53);
+ mpfr_set_prec (y, 53);
+ mpfr_set_str_binary (x, "0.10101100000000101001010101111111000000011111010000010E-1");
+ mpfr_rint (y, x, GMP_RNDU);
+ MPFR_ASSERTN(mpfr_cmp_ui (y, 1) == 0);
+ mpfr_rint (y, x, GMP_RNDD);
+ MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_POS(y));
+
+ mpfr_set_prec (x, 36);
+ mpfr_set_prec (y, 2);
+ mpfr_set_str_binary (x, "-11000110101010111111110111001.0000100");
+ mpfr_rint (y, x, GMP_RNDN);
+ mpfr_set_str_binary (x, "-11E27");
+ MPFR_ASSERTN(mpfr_cmp (y, x) == 0);
+
+ mpfr_set_prec (x, 39);
+ mpfr_set_prec (y, 29);
+ mpfr_set_str_binary (x, "-0.100010110100011010001111001001001100111E39");
+ mpfr_rint (y, x, GMP_RNDN);
+ mpfr_set_str_binary (x, "-0.10001011010001101000111100101E39");
+ MPFR_ASSERTN(mpfr_cmp (y, x) == 0);
+
+ mpfr_set_prec (x, 46);
+ mpfr_set_prec (y, 32);
+ mpfr_set_str_binary (x, "-0.1011100110100101000001011111101011001001101001E32");
+ mpfr_rint (y, x, GMP_RNDN);
+ mpfr_set_str_binary (x, "-0.10111001101001010000010111111011E32");
+ MPFR_ASSERTN(mpfr_cmp (y, x) == 0);
+
+ /* coverage test for mpfr_round */
+ mpfr_set_prec (x, 3);
+ mpfr_set_str_binary (x, "1.01E1"); /* 2.5 */
+ mpfr_set_prec (y, 2);
+ mpfr_round (y, x);
+ /* since mpfr_round breaks ties away, should give 3 and not 2 as with
+ the "round to even" rule */
+ MPFR_ASSERTN(mpfr_cmp_ui (y, 3) == 0);
+
+ mpfr_set_prec (x, 6);
+ mpfr_set_prec (y, 3);
mpfr_set_str_binary (x, "110.111");
mpfr_round (y, x);
if (mpfr_cmp_ui (y, 7))
@@ -39,6 +126,7 @@ special (void)
printf ("Error in round(110.111)\n");
exit (1);
}
+
mpfr_clear (x);
mpfr_clear (y);
}
diff --git a/tests/tround_prec.c b/tests/tround_prec.c
index 36b29dedd..b7e07c0fa 100644
--- a/tests/tround_prec.c
+++ b/tests/tround_prec.c
@@ -28,11 +28,48 @@ int
main (void)
{
mpfr_t x;
+ mp_exp_t emax;
tests_start_mpfr ();
- mpfr_init2 (x, 3);
+ mpfr_init (x);
+
+ mpfr_set_nan (x);
+ mpfr_prec_round (x, 2, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (x));
+
+ mpfr_set_inf (x, 1);
+ mpfr_prec_round (x, 2, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
+
+ mpfr_set_inf (x, -1);
+ mpfr_prec_round (x, 2, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0);
+
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_prec_round (x, 2, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x));
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_neg (x, x, GMP_RNDN);
+ mpfr_prec_round (x, 2, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_NEG(x));
+
+ emax = mpfr_get_emax ();
+ mpfr_set_emax (0);
+ mpfr_set_prec (x, 3);
+ mpfr_set_str_binary (x, "0.111");
+ mpfr_prec_round (x, 2, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
+ mpfr_set_emax (emax);
+
+ mpfr_set_prec (x, mp_bits_per_limb + 2);
+ mpfr_set_ui (x, 1, GMP_RNDN);
+ mpfr_nextbelow (x);
+ mpfr_prec_round (x, mp_bits_per_limb + 1, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0);
+
+ mpfr_set_prec (x, 3);
mpfr_set_ui (x, 5, GMP_RNDN);
mpfr_prec_round (x, 2, GMP_RNDN);
if (mpfr_cmp_ui(x, 4))
diff --git a/tests/tset.c b/tests/tset.c
index 877becfa7..5e86bf943 100644
--- a/tests/tset.c
+++ b/tests/tset.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_set.
-Copyright 2001, 2002, 2003 Free Software Foundation.
+Copyright 2001, 2002, 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library.
@@ -31,6 +31,7 @@ main (void)
mpfr_t x, y, z, u;
mp_rnd_t rnd;
int inexact, cmp;
+ mp_exp_t emax;
tests_start_mpfr ();
@@ -40,6 +41,36 @@ main (void)
inexact = mpfr_init_set_ui (z, 1, GMP_RNDN);
inexact = mpfr_init_set_d (u, 1.0, GMP_RNDN);
+ mpfr_set_nan (x);
+ mpfr_set (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_nan_p (y));
+
+ mpfr_set_inf (x, 1);
+ mpfr_set (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (y) && mpfr_sgn (y) > 0);
+
+ mpfr_set_inf (x, -1);
+ mpfr_set (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_inf_p (y) && mpfr_sgn (y) < 0);
+
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_set (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_POS(y));
+
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_neg (x, x, GMP_RNDN);
+ mpfr_set (y, x, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_NEG(y));
+
+ emax = mpfr_get_emax ();
+ mpfr_set_emax (0);
+ mpfr_set_prec (x, 3);
+ mpfr_set_str_binary (x, "0.111");
+ mpfr_set_prec (y, 2);
+ mpfr_set (y, x, GMP_RNDU);
+ MPFR_ASSERTN(mpfr_inf_p (y) && mpfr_sgn (y) > 0);
+ mpfr_set_emax (emax);
+
mpfr_set_prec (y, 11);
mpfr_set_str_binary (y, "0.11111111100E-8");
mpfr_set_prec (x, 2);