diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-01-22 22:30:52 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-01-22 22:30:52 +0000 |
commit | 031deac645662aea8a72a5ed0c0bf148e609e681 (patch) | |
tree | 07c68b885a0c39a228ca4b0f7f901a9117f85a9f /tests/terf.c | |
parent | 039c1c0135bac8353d17020543fe8b27f3b1937e (diff) | |
download | mpfr-031deac645662aea8a72a5ed0c0bf148e609e681.tar.gz |
added several hard-coded tests (and fixed bugs found)
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2644 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/terf.c')
-rw-r--r-- | tests/terf.c | 130 |
1 files changed, 120 insertions, 10 deletions
diff --git a/tests/terf.c b/tests/terf.c index 5d856d3c0..3dc4d6921 100644 --- a/tests/terf.c +++ b/tests/terf.c @@ -1,6 +1,6 @@ /* Test file for mpfr_erf. -Copyright 2001, 2002, 2003 Free Software Foundation, Inc. +Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc. Contributed by Ludovic Meunier and Paul Zimmermann. This file is part of the MPFR Library. @@ -29,25 +29,25 @@ MA 02111-1307, USA. */ #define TEST_FUNCTION mpfr_erf #include "tgeneric.c" -int -main (int argc, char *argv[]) +static void +special (void) { mpfr_t x, y; int inex; - tests_start_mpfr (); - mpfr_init2 (x, 53); mpfr_init2 (y, 53); + /* erf(NaN) = NaN */ mpfr_set_nan (x); mpfr_erf (y, x, GMP_RNDN); - if (mpfr_nan_p (y) == 0) + if (!mpfr_nan_p (y)) { printf ("mpfr_erf failed for x=NaN\n"); exit (1); } + /* erf(+Inf) = 1 */ mpfr_set_inf (x, 1); mpfr_erf (y, x, GMP_RNDN); if (mpfr_cmp_ui (y, 1)) @@ -59,6 +59,7 @@ main (int argc, char *argv[]) exit (1); } + /* erf(-Inf) = -1 */ mpfr_set_inf (x, -1); mpfr_erf (y, x, GMP_RNDN); if (mpfr_cmp_si (y, -1)) @@ -67,17 +68,19 @@ main (int argc, char *argv[]) exit (1); } - mpfr_set_ui (x, 0, GMP_RNDN); /* x = +0 */ + /* erf(+0) = +0 */ + mpfr_set_ui (x, 0, GMP_RNDN); mpfr_erf (y, x, GMP_RNDN); - if (mpfr_cmp_ui (y, 0) || MPFR_SIGN(y) < 0) + if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0) { printf ("mpfr_erf failed for x=+0\n"); exit (1); } - mpfr_neg (x, x, GMP_RNDN); /* x = -0 */ + /* erf(-0) = -0 */ + mpfr_neg (x, x, GMP_RNDN); mpfr_erf (y, x, GMP_RNDN); - if (mpfr_cmp_ui (y, 0) || MPFR_SIGN(y) > 0) + if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) > 0) { printf ("mpfr_erf failed for x=-0\n"); exit (1); @@ -195,8 +198,115 @@ main (int argc, char *argv[]) exit (1); } + mpfr_set_prec (x, 32); + mpfr_set_prec (y, 32); + + mpfr_set_str_binary (x, "0.1010100100111011001111100101E-1"); + mpfr_set_str_binary (y, "0.10111000001110011010110001101011E-1"); + mpfr_erf (x, x, GMP_RNDN); + if (mpfr_cmp (x, y)) + { + printf ("Error: erf for prec=32 (1)\n"); + exit (1); + } + + mpfr_set_str_binary (x, "-0.10110011011010111110010001100001"); + mpfr_set_str_binary (y, "-0.1010110110101011100010111000111"); + mpfr_erf (x, x, GMP_RNDN); + if (mpfr_cmp (x, y)) + { + printf ("Error: erf for prec=32 (2)\n"); + mpfr_print_binary (x); printf ("\n"); + exit (1); + } + + mpfr_set_str_binary (x, "100.10001110011110100000110000111"); + mpfr_set_str_binary (y, "0.11111111111111111111111111111111"); + mpfr_erf (x, x, GMP_RNDN); + if (mpfr_cmp (x, y)) + { + printf ("Error: erf for prec=32 (3)\n"); + exit (1); + } + mpfr_set_str_binary (x, "100.10001110011110100000110000111"); + mpfr_erf (x, x, GMP_RNDZ); + if (mpfr_cmp (x, y)) + { + printf ("Error: erf for prec=32 (4)\n"); + exit (1); + } + mpfr_set_str_binary (x, "100.10001110011110100000110000111"); + mpfr_erf (x, x, GMP_RNDU); + if (mpfr_cmp_ui (x, 1)) + { + printf ("Error: erf for prec=32 (5)\n"); + exit (1); + } + + mpfr_set_str_binary (x, "100.10001110011110100000110001000"); + mpfr_erf (x, x, GMP_RNDN); + if (mpfr_cmp_ui (x, 1)) + { + printf ("Error: erf for prec=32 (6)\n"); + exit (1); + } + mpfr_set_str_binary (x, "100.10001110011110100000110001000"); + mpfr_set_str_binary (y, "0.11111111111111111111111111111111"); + mpfr_erf (x, x, GMP_RNDZ); + if (mpfr_cmp (x, y)) + { + printf ("Error: erf for prec=32 (7)\n"); + exit (1); + } + mpfr_set_str_binary (x, "100.10001110011110100000110001000"); + mpfr_erf (x, x, GMP_RNDU); + if (mpfr_cmp_ui (x, 1)) + { + printf ("Error: erf for prec=32 (8)\n"); + exit (1); + } + + mpfr_set_ui (x, 5, GMP_RNDN); + mpfr_erf (x, x, GMP_RNDN); + if (mpfr_cmp_ui (x, 1)) + { + printf ("Error: erf for prec=32 (9)\n"); + exit (1); + } + mpfr_set_ui (x, 5, GMP_RNDN); + mpfr_erf (x, x, GMP_RNDU); + if (mpfr_cmp_ui (x, 1)) + { + printf ("Error: erf for prec=32 (10)\n"); + exit (1); + } + mpfr_set_ui (x, 5, GMP_RNDN); + mpfr_erf (x, x, GMP_RNDZ); + mpfr_set_str_binary (y, "0.11111111111111111111111111111111"); + if (mpfr_cmp (x, y)) + { + printf ("Error: erf for prec=32 (11)\n"); + exit (1); + } + mpfr_set_ui (x, 5, GMP_RNDN); + mpfr_erf (x, x, GMP_RNDD); + mpfr_set_str_binary (y, "0.11111111111111111111111111111111"); + if (mpfr_cmp (x, y)) + { + printf ("Error: erf for prec=32 (12)\n"); + exit (1); + } + mpfr_clear (x); mpfr_clear (y); +} + +int +main (int argc, char *argv[]) +{ + tests_start_mpfr (); + + special (); test_generic (2, 100, 10); |