diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-02-14 23:05:51 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-02-14 23:05:51 +0000 |
commit | 6e5ffc68a8061e42a2680dd99455f89e2f4f8ca9 (patch) | |
tree | 3150eedf9dc6ae8d160042147ff46ac533e723dd /tests | |
parent | f095a6c8a44a63379841097ddfbf4682e56e4036 (diff) | |
download | mpfr-6e5ffc68a8061e42a2680dd99455f89e2f4f8ca9.tar.gz |
new coverage tests
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2714 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/tset_d.c | 28 | ||||
-rw-r--r-- | tests/tset_exp.c | 59 | ||||
-rw-r--r-- | tests/tset_f.c | 50 | ||||
-rw-r--r-- | tests/tset_ld.c | 27 | ||||
-rw-r--r-- | tests/tset_si.c | 18 | ||||
-rw-r--r-- | tests/tset_str.c | 34 | ||||
-rw-r--r-- | tests/tset_z.c | 27 | ||||
-rw-r--r-- | tests/tsin.c | 9 | ||||
-rw-r--r-- | tests/tsin_cos.c | 19 | ||||
-rw-r--r-- | tests/tsinh.c | 36 | ||||
-rw-r--r-- | tests/tsqrt.c | 49 | ||||
-rw-r--r-- | tests/ttan.c | 9 | ||||
-rw-r--r-- | tests/ttanh.c | 31 | ||||
-rw-r--r-- | tests/tui_div.c | 21 | ||||
-rw-r--r-- | tests/tui_pow.c | 7 | ||||
-rw-r--r-- | tests/tui_sub.c | 8 |
17 files changed, 401 insertions, 33 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 0214ac889..e35b1b8da 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ 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 tinp_str +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 tset_exp EXTRA_DIST = tgeneric.c mpf_compat.h inp_str.data diff --git a/tests/tset_d.c b/tests/tset_d.c index 865e5d071..0ba0b9ba9 100644 --- a/tests/tset_d.c +++ b/tests/tset_d.c @@ -36,7 +36,33 @@ main (int argc, char *argv[]) tests_start_mpfr (); mpfr_test_init (); - mpfr_init2 (x, 2); + mpfr_init (x); + + d = 0.0; + mpfr_set_d (x, d, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x)); + mpfr_set_d (x, -d, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_NEG(x)); + + mpfr_set_nan (x); + d = mpfr_get_d (x, GMP_RNDN); + mpfr_set_ui (x, 0, GMP_RNDN); + mpfr_set_d (x, d, GMP_RNDN); + MPFR_ASSERTN(mpfr_nan_p (x)); + + mpfr_set_inf (x, 1); + d = mpfr_get_d (x, GMP_RNDN); + mpfr_set_ui (x, 0, GMP_RNDN); + mpfr_set_d (x, d, GMP_RNDN); + MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0); + + mpfr_set_inf (x, -1); + d = mpfr_get_d (x, GMP_RNDN); + mpfr_set_ui (x, 0, GMP_RNDN); + mpfr_set_d (x, d, GMP_RNDN); + MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0); + + mpfr_set_prec (x, 2); /* checks that denormalized are not flushed to zero */ d = DBL_MIN; /* 2^(-1022) */ diff --git a/tests/tset_exp.c b/tests/tset_exp.c new file mode 100644 index 000000000..27381345a --- /dev/null +++ b/tests/tset_exp.c @@ -0,0 +1,59 @@ +/* Test file for mpfr_set_exp. + +Copyright 2004 Free Software Foundation. + +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; + int ret; + + tests_start_mpfr (); + + mpfr_init (x); + + mpfr_set_ui (x, 1, GMP_RNDN); + ret = mpfr_set_exp (x, 2); + MPFR_ASSERTN(ret == 0 && mpfr_cmp_ui (x, 2) == 0); + + mpfr_set_emin (-1); + ret = mpfr_set_exp (x, -1); + MPFR_ASSERTN(ret == 0 && mpfr_cmp_ui_2exp (x, 1, -2) == 0); + + mpfr_set_emax (1); + ret = mpfr_set_exp (x, 1); + MPFR_ASSERTN(ret == 0 && mpfr_cmp_ui (x, 1) == 0); + + ret = mpfr_set_exp (x, -2); + MPFR_ASSERTN(ret != 0 && mpfr_cmp_ui (x, 1) == 0); + + ret = mpfr_set_exp (x, 2); + MPFR_ASSERTN(ret != 0 && mpfr_cmp_ui (x, 1) == 0); + + mpfr_clear (x); + + tests_end_mpfr (); + return 0; +} diff --git a/tests/tset_f.c b/tests/tset_f.c index 37c80485c..e361e6b0d 100644 --- a/tests/tset_f.c +++ b/tests/tset_f.c @@ -35,8 +35,8 @@ main (void) tests_start_mpfr (); - mpf_init(y); - mpf_init(z); + mpf_init (y); + mpf_init (z); mpf_set_d (y, 0.0); @@ -45,33 +45,33 @@ main (void) mpfr_set_prec (x, 100); mpfr_set_f (x, y, GMP_RNDN); - mpf_random2(y, 10, 0); - mpfr_set_f(x, y, RND_RAND() ); + mpf_random2 (y, 10, 0); + mpfr_set_f (x, y, RND_RAND() ); /* bug found by Jean-Pierre Merlet */ - mpfr_set_prec(x, 256); - mpf_set_prec(y, 256); - mpfr_init2(u, 256); - mpfr_set_str(u, + mpfr_set_prec (x, 256); + mpf_set_prec (y, 256); + mpfr_init2 (u, 256); + mpfr_set_str (u, "7.f10872b020c49ba5e353f7ced916872b020c49ba5e353f7ced916872b020c498@2", 16, GMP_RNDN); - mpf_set_str(y, "2033.033", 10); - mpfr_set_f(x, y, GMP_RNDN); - if (mpfr_cmp(x, u)) + mpf_set_str (y, "2033.033", 10); + mpfr_set_f (x, y, GMP_RNDN); + if (mpfr_cmp (x, u)) { printf ("mpfr_set_f failed for y=2033.033\n"); exit (1); } - mpf_set_str(y, "-2033.033", 10); - mpfr_set_f(x, y, GMP_RNDN); - mpfr_neg(u, u, GMP_RNDN); - if (mpfr_cmp(x, u)) + mpf_set_str (y, "-2033.033", 10); + mpfr_set_f (x, y, GMP_RNDN); + mpfr_neg (u, u, GMP_RNDN); + if (mpfr_cmp (x, u)) { printf ("mpfr_set_f failed for y=-2033.033\n"); exit (1); } - mpfr_clear(u); + mpfr_clear (u); for (k = 1; k <= 100000; k++) { @@ -83,9 +83,9 @@ main (void) } /* Check for +0 */ - mpfr_set_prec(x, 53); - mpf_set_prec(y, 53); - mpf_set_ui(y, 0); + mpfr_set_prec (x, 53); + mpf_set_prec (y, 53); + mpf_set_ui (y, 0); for(r = 0 ; r < GMP_RND_MAX ; r++) { inexact = mpfr_set_f(x, y, r); @@ -97,6 +97,18 @@ main (void) } } + /* coverage test */ + mpf_set_prec (y, 2); + mpfr_set_prec (x, 3 * mp_bits_per_limb); + mpf_set_ui (y, 1); + for (r = 0; r < mp_bits_per_limb; r++) + { + mpfr_random (x); /* to fill low limbs with random data */ + inexact = mpfr_set_f (x, y, GMP_RNDN); + MPFR_ASSERTN(inexact == 0 && mpfr_cmp_ui_2exp (x, 1, r) == 0); + mpf_mul_2exp (y, y, 1); + } + mpfr_clear (x); mpf_clear (y); mpf_clear (z); diff --git a/tests/tset_ld.c b/tests/tset_ld.c index 43407eb89..b368176e6 100644 --- a/tests/tset_ld.c +++ b/tests/tset_ld.c @@ -1,6 +1,6 @@ /* Test file for mpfr_set_ld and mpfr_get_ld. -Copyright 2002, 2003 Free Software Foundation, Inc. +Copyright 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of the MPFR Library. @@ -59,12 +59,16 @@ check_set_get (long double d, mpfr_t x) { mp_rnd_t r; long double e; + int inex; - for (r=0; r<4; r++) + for (r = 0; r < 4; r++) { - if (mpfr_set_ld (x, d, r)) + if (inex = mpfr_set_ld (x, d, r)) { printf ("Error: mpfr_set_ld should be exact\n"); + printf ("d=%1.30Le inex=%d\n", d, inex); + printf ("emin=%ld emax=%ld\n", mpfr_get_emin (), mpfr_get_emax ()); + mpfr_dump (x); exit (1); } e = mpfr_get_ld (x, r); @@ -88,6 +92,7 @@ main (int argc, char *argv[]) long double d, e; mpfr_t x; int i; + mp_exp_t emax; check_gcc33_bug (); @@ -148,7 +153,7 @@ main (int argc, char *argv[]) /* checks that 2^i, 2^i+1 and 2^i-1 are correctly converted */ d = 1.0; - for (i=1; i<=113; i++) + for (i = 1; i <= 113; i++) { d = 2.0 * d; /* d = 2^i */ check_set_get (d, x); @@ -156,13 +161,25 @@ main (int argc, char *argv[]) check_set_get (d - 1.0, x); } - for (i=0; i<10000; i++) + for (i = 0; i < 10000; i++) { mpfr_random (x); d = mpfr_get_ld (x, GMP_RNDN); check_set_get (d, x); } + /* check with reduced emax to exercise overflow */ + emax = mpfr_get_emax (); + mpfr_set_prec (x, 2); + mpfr_set_emax (1); + mpfr_set_ld (x, (long double) 2.0, GMP_RNDN); + MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0); + for (d = (long double) 2.0, i = 0; i < 13; i++, d *= d); + /* now d = 2^8192 */ + mpfr_set_ld (x, d, GMP_RNDN); + MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0); + mpfr_set_emax (emax); + mpfr_clear (x); tests_end_mpfr (); diff --git a/tests/tset_si.c b/tests/tset_si.c index b880fe363..e3e1fb85f 100644 --- a/tests/tset_si.c +++ b/tests/tset_si.c @@ -37,6 +37,7 @@ main (int argc, char *argv[]) unsigned long zl, dl; int inex; mp_rnd_t r; + mp_exp_t emax; tests_start_mpfr (); @@ -152,6 +153,7 @@ main (int argc, char *argv[]) } /* check potential bug in case mp_limb_t is unsigned */ + emax = mpfr_get_emax (); mpfr_set_emax (0); mpfr_set_si (x, -1, GMP_RNDN); if (mpfr_sgn (x) >= 0) @@ -159,7 +161,9 @@ main (int argc, char *argv[]) printf ("mpfr_set_si (x, -1) fails\n"); exit (1); } + mpfr_set_emax (emax); + emax = mpfr_get_emax (); mpfr_set_emax (5); mpfr_set_prec (x, 2); mpfr_set_si (x, -31, GMP_RNDN); @@ -168,6 +172,7 @@ main (int argc, char *argv[]) printf ("mpfr_set_si (x, -31) fails\n"); exit (1); } + mpfr_set_emax (emax); /* test for get_ui */ mpfr_set_ui (x, 0, GMP_RNDN); @@ -176,6 +181,19 @@ main (int argc, char *argv[]) mpfr_nextabove (x); mpfr_get_ui (x, GMP_RNDU); + /* coverage tests */ + mpfr_set_prec (x, 2); + mpfr_set_si (x, -7, GMP_RNDD); + MPFR_ASSERTN(mpfr_cmp_si (x, -8) == 0); + mpfr_set_prec (x, 2); + mpfr_set_ui (x, 7, GMP_RNDU); + MPFR_ASSERTN(mpfr_cmp_ui (x, 8) == 0); + emax = mpfr_get_emax (); + mpfr_set_emax (3); + mpfr_set_ui (x, 7, GMP_RNDU); + MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0); + mpfr_set_emax (emax); + mpfr_clear (x); tests_end_mpfr (); diff --git a/tests/tset_str.c b/tests/tset_str.c index b0c62c7fa..3427ed341 100644 --- a/tests/tset_str.c +++ b/tests/tset_str.c @@ -1,6 +1,6 @@ /* Test file for mpfr_set_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. @@ -36,7 +36,7 @@ main (int argc, char *argv[]) unsigned long k, bd, nc, i; char *str, *str2; mp_exp_t e; - int base, logbase, prec, baseprec; + int base, logbase, prec, baseprec, ret; tests_start_mpfr (); @@ -446,6 +446,36 @@ main (int argc, char *argv[]) exit (1); } + /* check invalid input */ + mpfr_set_ui (x, 1, GMP_RNDN); + ret = mpfr_set_str (x, "1", 37, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0 && ret == -1); + ret = mpfr_set_str (x, "1E10toto", 10, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0 && ret == -1); + ret = mpfr_set_str (x, "1p10toto", 16, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0 && ret == -1); + ret = mpfr_set_str (x, "this_is_an_invalid_number_in_base_36", 36, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0 && ret == -1); + mpfr_set_prec (x, 135); + ret = mpfr_set_str (x, "thisisavalidnumberinbase36", 36, GMP_RNDN); + mpfr_set_prec (y, 135); + mpfr_set_str (y, "23833565676460972739462619524519814462546", 10, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp (x, y) == 0 && ret == 0); + + /* coverage test for set_str_binary */ + mpfr_set_str_binary (x, "NaN"); + MPFR_ASSERTN(mpfr_nan_p (x)); + mpfr_set_str_binary (x, "Inf"); + MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0); + mpfr_set_str_binary (x, "+Inf"); + MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0); + mpfr_set_str_binary (x, "-Inf"); + MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0); + mpfr_set_prec (x, 3); + mpfr_set_str_binary (x, "0.01E2"); + MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0); + mpfr_set_str_binary (x, "-0.01E2"); + MPFR_ASSERTN(mpfr_cmp_si (x, -1) == 0); mpfr_clear (x); mpfr_clear (y); diff --git a/tests/tset_z.c b/tests/tset_z.c index 630b6e950..f0f49f5fc 100644 --- a/tests/tset_z.c +++ b/tests/tset_z.c @@ -77,10 +77,12 @@ check_large (void) { mpz_t z; mpfr_t x, y; + mp_exp_t emax, emin; mpz_init (z); mpfr_init2 (x, 160); mpfr_init2 (y, 160); + mpz_set_str (z, "77031627725494291259359895954016675357279104942148788042", 10); mpfr_set_z (x, z, GMP_RNDN); mpfr_set_str_binary (y, "0.1100100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111000001001E186"); @@ -89,6 +91,31 @@ check_large (void) printf ("Error in mpfr_set_z on large input\n"); exit (1); } + + /* check overflow */ + emax = mpfr_get_emax (); + mpfr_set_emax (2); + mpz_set_str (z, "7", 10); + mpfr_set_z (x, z, GMP_RNDU); + MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0); + mpfr_set_emax (3); + mpfr_set_prec (x, 2); + mpz_set_str (z, "7", 10); + mpfr_set_z (x, z, GMP_RNDU); + MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0); + mpfr_set_emax (emax); + + /* check underflow */ + emin = mpfr_get_emin (); + mpfr_set_emin (3); + mpz_set_str (z, "1", 10); + mpfr_set_z (x, z, GMP_RNDZ); + MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x)); + mpfr_set_emin (2); + mpfr_set_z (x, z, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x)); + mpfr_set_emin (emin); + mpz_clear (z); mpfr_clear (x); mpfr_clear (y); diff --git a/tests/tsin.c b/tests/tsin.c index 604dbb245..b8a6651f0 100644 --- a/tests/tsin.c +++ b/tests/tsin.c @@ -81,6 +81,15 @@ test_sign (void) exit (1); } } + + /* worst case on 53 bits */ + mpfr_set_prec (x, 53); + mpfr_set_prec (y, 53); + mpfr_set_str (x, "6134899525417045", 10, GMP_RNDN); + mpfr_sin (y, x, GMP_RNDN); + mpfr_set_str_binary (x, "11011010111101011110111100010101010101110000000001011E-106"); + MPFR_ASSERTN(mpfr_cmp (x, y) == 0); + mpfr_clear (pid); mpfr_clear (piu); mpfr_clear (x); diff --git a/tests/tsin_cos.c b/tests/tsin_cos.c index c7de6d50c..08a12b267 100644 --- a/tests/tsin_cos.c +++ b/tests/tsin_cos.c @@ -140,6 +140,25 @@ check_nans (void) MPFR_ASSERTN (mpfr_nan_p (s)); MPFR_ASSERTN (mpfr_nan_p (c)); + /* check zero */ + mpfr_set_ui (x, 0, GMP_RNDN); + mpfr_sin_cos (s, c, x, GMP_RNDN); + MPFR_ASSERTN (mpfr_cmp_ui (s, 0) == 0 && MPFR_IS_POS (s)); + MPFR_ASSERTN (mpfr_cmp_ui (c, 1) == 0); + mpfr_neg (x, x, GMP_RNDN); + mpfr_sin_cos (s, c, x, GMP_RNDN); + MPFR_ASSERTN (mpfr_cmp_ui (s, 0) == 0 && MPFR_IS_NEG (s)); + MPFR_ASSERTN (mpfr_cmp_ui (c, 1) == 0); + + /* coverage test */ + mpfr_set_prec (x, 2); + mpfr_set_ui (x, 4, GMP_RNDN); + mpfr_set_prec (s, 2); + mpfr_set_prec (c, 2); + mpfr_sin_cos (s, c, x, GMP_RNDN); + MPFR_ASSERTN (mpfr_cmp_si_2exp (s, -3, -2) == 0); + MPFR_ASSERTN (mpfr_cmp_si_2exp (c, -3, -2) == 0); + mpfr_clear (x); mpfr_clear (s); mpfr_clear (c); diff --git a/tests/tsinh.c b/tests/tsinh.c index 1739e35c6..e2e76983b 100644 --- a/tests/tsinh.c +++ b/tests/tsinh.c @@ -1,6 +1,6 @@ /* Test file for mpfr_sinh. -Copyright 2001, 2002 Free Software Foundation. +Copyright 2001, 2002, 2004 Free Software Foundation. Adapted from tarctan.c. This file is part of the MPFR Library. @@ -28,11 +28,45 @@ MA 02111-1307, USA. */ #define TEST_FUNCTION mpfr_sinh #include "tgeneric.c" +static void +special (void) +{ + mpfr_t x; + + mpfr_init (x); + + mpfr_set_nan (x); + mpfr_sinh (x, x, GMP_RNDN); + MPFR_ASSERTN(mpfr_nan_p (x)); + + mpfr_set_inf (x, 1); + mpfr_sinh (x, x, GMP_RNDN); + MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0); + mpfr_set_inf (x, -1); + mpfr_sinh (x, x, GMP_RNDN); + MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0); + + mpfr_set_prec (x, 10); + mpfr_set_str_binary (x, "-0.1001011001"); + mpfr_sinh (x, x, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_si_2exp (x, -159, -8) == 0); + + /* corner case */ + mpfr_set_prec (x, 2); + mpfr_set_str_binary (x, "1E-6"); + mpfr_sinh (x, x, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_ui_2exp (x, 1, -6) == 0); + + mpfr_clear (x); +} + int main (int argc, char *argv[]) { tests_start_mpfr (); + special (); + test_generic (2, 100, 100); tests_end_mpfr (); diff --git a/tests/tsqrt.c b/tests/tsqrt.c index 3acc7749f..228e1423c 100644 --- a/tests/tsqrt.c +++ b/tests/tsqrt.c @@ -140,6 +140,7 @@ special (void) mpfr_t x, z; int inexact; mp_prec_t p; + mp_rnd_t r; mpfr_init (x); mpfr_init (z); @@ -227,6 +228,54 @@ special (void) exit (1); } + /* case prec(result) << prec(input) */ + mpfr_set_prec (z, 2); + for (p = 2; p < 1000; p++) + { + mpfr_set_prec (x, p); + mpfr_set_ui (x, 1, GMP_RNDN); + mpfr_nextabove (x); + /* 1.0 < x <= 1.5 thus 1 < sqrt(x) <= 1.23 */ + inexact = mpfr_sqrt (z, x, GMP_RNDN); + MPFR_ASSERTN(inexact < 0 && mpfr_cmp_ui (z, 1) == 0); + inexact = mpfr_sqrt (z, x, GMP_RNDZ); + MPFR_ASSERTN(inexact < 0 && mpfr_cmp_ui (z, 1) == 0); + inexact = mpfr_sqrt (z, x, GMP_RNDU); + MPFR_ASSERTN(inexact > 0 && mpfr_cmp_ui_2exp (z, 3, -1) == 0); + inexact = mpfr_sqrt (z, x, GMP_RNDD); + MPFR_ASSERTN(inexact < 0 && mpfr_cmp_ui (z, 1) == 0); + } + + /* corner case rw = 0 in rounding to nearest */ + mpfr_set_prec (z, mp_bits_per_limb - 1); + for (p = 2 * mp_bits_per_limb - 1; p <= 1000; p++) + { + mpfr_set_prec (x, p); + mpfr_set_ui (x, 1, GMP_RNDN); + mpfr_set_exp (x, mp_bits_per_limb); + mpfr_add_ui (x, x, 1, GMP_RNDN); + /* now x = 2^(mp_bits_per_limb - 1) + 1 (mp_bits_per_limb bits) */ + MPFR_ASSERTN(mpfr_mul (x, x, x, GMP_RNDN) == 0); /* exact */ + inexact = mpfr_sqrt (z, x, GMP_RNDN); + /* even rule: z should be 2^(mp_bits_per_limb - 1) */ + MPFR_ASSERTN(inexact < 0 && + mpfr_cmp_ui_2exp (z, 1, mp_bits_per_limb - 1) == 0); + mpfr_nextbelow (x); + /* now x is just below [2^(mp_bits_per_limb - 1) + 1]^2 */ + inexact = mpfr_sqrt (z, x, GMP_RNDN); + MPFR_ASSERTN(inexact < 0 && + mpfr_cmp_ui_2exp (z, 1, mp_bits_per_limb - 1) == 0); + mpfr_nextabove (x); + mpfr_nextabove (x); + /* now x is just above [2^(mp_bits_per_limb - 1) + 1]^2 */ + inexact = mpfr_sqrt (z, x, GMP_RNDN); + if (inexact <= 0 || mpfr_cmp_ui_2exp (z, 1, mp_bits_per_limb - 1) == 0) + { + printf ("Error in corner case for p=%u\n", p); + exit (1); + } + } + mpfr_clear (x); mpfr_clear (z); } diff --git a/tests/ttan.c b/tests/ttan.c index 81dfdee42..bcda94716 100644 --- a/tests/ttan.c +++ b/tests/ttan.c @@ -59,6 +59,15 @@ check_nans (void) exit (1); } + /* exercise recomputation */ + mpfr_set_prec (x, 14); + mpfr_set_str_binary (x, "0.10100000101010E0"); + mpfr_set_prec (y, 24); + mpfr_tan (y, x, GMP_RNDU); + mpfr_set_prec (x, 24); + mpfr_set_str_binary (x, "101110011011001100100001E-24"); + MPFR_ASSERTN(mpfr_cmp (x, y) == 0); + mpfr_clear (x); mpfr_clear (y); } diff --git a/tests/ttanh.c b/tests/ttanh.c index 15e6f5efd..2af3093d7 100644 --- a/tests/ttanh.c +++ b/tests/ttanh.c @@ -1,6 +1,6 @@ /* Test file for mpfr_tanh. -Copyright 2001, 2002, 2003 Free Software Foundation. +Copyright 2001, 2002, 2003, 2004 Free Software Foundation. Adapted from tarctan.c. This file is part of the MPFR Library. @@ -28,11 +28,40 @@ MA 02111-1307, USA. */ #define TEST_FUNCTION mpfr_tanh #include "tgeneric.c" +static void +special (void) +{ + mpfr_t x; + + mpfr_init (x); + + mpfr_set_nan (x); + mpfr_tanh (x, x, GMP_RNDN); + MPFR_ASSERTN(mpfr_nan_p (x)); + + mpfr_set_inf (x, 1); + mpfr_tanh (x, x, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0); + + mpfr_set_inf (x, -1); + mpfr_tanh (x, x, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_si (x, -1) == 0); + + mpfr_set_prec (x, 10); + mpfr_set_str_binary (x, "-0.1001011001"); + mpfr_tanh (x, x, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_si_2exp (x, -135, -8) == 0); + + mpfr_clear (x); +} + int main (int argc, char *argv[]) { tests_start_mpfr (); + special (); + test_generic (2, 100, 100); tests_end_mpfr (); diff --git a/tests/tui_div.c b/tests/tui_div.c index 2f0512218..56134776f 100644 --- a/tests/tui_div.c +++ b/tests/tui_div.c @@ -134,6 +134,27 @@ check_nan (void) MPFR_ASSERTN (mpfr_ui_div (q, 0L, d, GMP_RNDZ) == 0); /* exact */ MPFR_ASSERTN (mpfr_nan_p (q)); + /* 1/+0 = +inf */ + mpfr_set_ui (d, 0L, GMP_RNDN); + MPFR_ASSERTN (mpfr_ui_div (q, 1L, d, GMP_RNDZ) == 0); /* exact */ + MPFR_ASSERTN (mpfr_inf_p (q) && mpfr_sgn (q) > 0); + + /* 1/-0 = -inf */ + mpfr_set_ui (d, 0L, GMP_RNDN); + mpfr_neg (d, d, GMP_RNDN); + MPFR_ASSERTN (mpfr_ui_div (q, 1L, d, GMP_RNDZ) == 0); /* exact */ + MPFR_ASSERTN (mpfr_inf_p (q) && mpfr_sgn (q) < 0); + + /* 0/1 = +0 */ + mpfr_set_ui (d, 1L, GMP_RNDN); + MPFR_ASSERTN (mpfr_ui_div (q, 0L, d, GMP_RNDZ) == 0); /* exact */ + MPFR_ASSERTN (mpfr_cmp_ui (q, 0) == 0 && MPFR_IS_POS (q)); + + /* 0/-1 = -0 */ + mpfr_set_si (d, -1, GMP_RNDN); + MPFR_ASSERTN (mpfr_ui_div (q, 0L, d, GMP_RNDZ) == 0); /* exact */ + MPFR_ASSERTN (mpfr_cmp_ui (q, 0) == 0 && MPFR_IS_NEG (q)); + mpfr_clear (d); mpfr_clear (q); } diff --git a/tests/tui_pow.c b/tests/tui_pow.c index 4da7010cf..99aebef56 100644 --- a/tests/tui_pow.c +++ b/tests/tui_pow.c @@ -1,6 +1,6 @@ -/* Test file for mpfr_ui_pow. +/* Test file for mpfr_ui_pow and mpfr_ui_pow_ui. -Copyright 2001, 2002, 2003 Free Software Foundation. +Copyright 2001, 2002, 2003, 2004 Free Software Foundation. Adapted from tarctan.c. This file is part of the MPFR Library. @@ -49,6 +49,9 @@ test1 (void) exit (1); } + mpfr_ui_pow_ui (x, 0, 1, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS (x)); + mpfr_clear (x); mpfr_clear (y); } diff --git a/tests/tui_sub.c b/tests/tui_sub.c index b2eaa5b8f..c3a83ef05 100644 --- a/tests/tui_sub.c +++ b/tests/tui_sub.c @@ -1,6 +1,6 @@ /* Test file for mpfr_ui_sub. -Copyright 2000, 2001, 2002, 2003 Free Software Foundation. +Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation. This file is part of the MPFR Library. @@ -120,6 +120,12 @@ special (void) exit (1); } + mpfr_set_prec (x, 10); + mpfr_set_prec (y, 10); + mpfr_random (x); + mpfr_ui_sub (y, 0, x, GMP_RNDN); + MPFR_ASSERTN(mpfr_cmpabs (x, y) == 0 && mpfr_sgn (x) != mpfr_sgn (y)); + mpfr_clear (x); mpfr_clear (y); mpfr_clear (res); |