diff options
author | thevenyp <thevenyp@280ebfd0-de03-0410-8827-d642c229c3f4> | 2007-09-11 13:01:54 +0000 |
---|---|---|
committer | thevenyp <thevenyp@280ebfd0-de03-0410-8827-d642c229c3f4> | 2007-09-11 13:01:54 +0000 |
commit | 5e318e2944fa3d5de3f58c4ec1ab2224d4873008 (patch) | |
tree | 684929f665eaba133e642665b1cde1fd0b04ecd3 /tests | |
parent | a10a8c4f72d895d795d20749b7ba79fed4c95b17 (diff) | |
download | mpfr-5e318e2944fa3d5de3f58c4ec1ab2224d4873008.tar.gz |
add some simple test cases in tadd_d.c and friends
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@4837 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tadd_d.c | 62 | ||||
-rw-r--r-- | tests/td_div.c | 31 | ||||
-rw-r--r-- | tests/td_sub.c | 32 | ||||
-rw-r--r-- | tests/tdiv_d.c | 31 | ||||
-rw-r--r-- | tests/tmul_d.c | 31 | ||||
-rw-r--r-- | tests/tsub_d.c | 31 |
6 files changed, 218 insertions, 0 deletions
diff --git a/tests/tadd_d.c b/tests/tadd_d.c index fb761c67c..b7a051a42 100644 --- a/tests/tadd_d.c +++ b/tests/tadd_d.c @@ -27,6 +27,67 @@ MA 02110-1301, USA. */ #include "mpfr-test.h" static void +check_regulars (void) +{ + mpfr_t x, y, z; + double d; + int inexact; + + /* (1) check with enough precision */ + mpfr_init2 (x, IEEE_DBL_MANT_DIG); + mpfr_init2 (y, IEEE_DBL_MANT_DIG); + mpfr_init2 (z, IEEE_DBL_MANT_DIG); + + mpfr_set_str (y, "4096", 10, GMP_RNDN); + d = 0.125; + mpfr_clear_flags (); + inexact = mpfr_add_d (x, y, d, GMP_RNDN); + if (inexact != 0) + { + printf ("Inexact flag error in mpfr_add_d (1)\n"); + exit (1); + } + mpfr_set_str (z, "4096.125", 10, GMP_RNDN); + if (mpfr_cmp (z, x)) + { + printf ("Error in mpfr_add_d ("); + mpfr_out_str (stdout, 10, 7, y, GMP_RNDN); + printf (" + %.20g)\nexpected ", d); + mpfr_out_str (stdout, 10, 0, z, GMP_RNDN); + printf ("\ngot "); + mpfr_out_str (stdout, 10, 0, x, GMP_RNDN); + printf ("\n"); + exit (1); + } + + /* (2) check inexact flag */ + mpfr_set_prec (x, 2); + mpfr_set_prec (z, 2); + + mpfr_clear_flags (); + inexact = mpfr_add_d (x, y, d, GMP_RNDN); + if (inexact == 0) + { + printf ("Inexact flag error in mpfr_add_d (2)\n"); + exit (1); + } + mpfr_set_str (z, "4096.125", 10, GMP_RNDN); + if (mpfr_cmp (z, x)) + { + printf ("Error in mpfr_add_d ("); + mpfr_out_str (stdout, 10, 0, y, GMP_RNDN); + printf (" + %.20g)\nexpected ", d); + mpfr_out_str (stdout, 10, 0, z, GMP_RNDN); + printf ("\ngot "); + mpfr_out_str (stdout, 10, 0, x, GMP_RNDN); + printf ("\n"); + exit (1); + } + + mpfr_clears (x, y, z, (void *) 0); +} + +static void check_nans (void) { mpfr_t x, y; @@ -67,6 +128,7 @@ main (int argc, char *argv[]) tests_start_mpfr (); check_nans (); + check_regulars (); test_generic (2, 1000, 100); diff --git a/tests/td_div.c b/tests/td_div.c index 530300582..e50f6e6f4 100644 --- a/tests/td_div.c +++ b/tests/td_div.c @@ -69,9 +69,40 @@ check_nans (void) int main (int argc, char *argv[]) { + mpfr_t x, y, z; + double d; + int inexact; MPFR_TEST_USE_RANDS (); tests_start_mpfr (); + /* check with enough precision */ + mpfr_init2 (x, IEEE_DBL_MANT_DIG); + mpfr_init2 (y, IEEE_DBL_MANT_DIG); + mpfr_init2 (z, IEEE_DBL_MANT_DIG); + + mpfr_set_str (y, "4096", 10, GMP_RNDN); + d = 0.125; + mpfr_clear_flags (); + inexact = mpfr_d_div (x, d, y, GMP_RNDN); + if (inexact != 0) + { + printf ("Inexact flag error in mpfr_d_div\n"); + exit (1); + } + mpfr_set_str (z, " 0.000030517578125", 10, GMP_RNDN); + if (mpfr_cmp (z, x)) + { + printf ("Error in mpfr_d_div ("); + mpfr_out_str (stdout, 10, 0, y, GMP_RNDN); + printf (" + %.20g)\nexpected ", d); + mpfr_out_str (stdout, 10, 0, z, GMP_RNDN); + printf ("\ngot "); + mpfr_out_str (stdout, 10, 0, x, GMP_RNDN); + printf ("\n"); + exit (1); + } + mpfr_clears (x, y, z, (void *)0); + check_nans (); test_generic (2, 1000, 100); diff --git a/tests/td_sub.c b/tests/td_sub.c index 732684ea9..a51a8c632 100644 --- a/tests/td_sub.c +++ b/tests/td_sub.c @@ -63,9 +63,41 @@ check_nans (void) int main (int argc, char *argv[]) { + mpfr_t x, y, z; + double d; + int inexact; + MPFR_TEST_USE_RANDS (); tests_start_mpfr (); + /* check with enough precision */ + mpfr_init2 (x, IEEE_DBL_MANT_DIG); + mpfr_init2 (y, IEEE_DBL_MANT_DIG); + mpfr_init2 (z, IEEE_DBL_MANT_DIG); + + mpfr_set_str (y, "4096", 10, GMP_RNDN); + d = 0.125; + mpfr_clear_flags (); + inexact = mpfr_d_sub (x, d, y, GMP_RNDN); + if (inexact != 0) + { + printf ("Inexact flag error in mpfr_d_sub\n"); + exit (1); + } + mpfr_set_str (z, "-4095.875", 10, GMP_RNDN); + if (mpfr_cmp (z, x)) + { + printf ("Error in mpfr_d_sub ("); + mpfr_out_str (stdout, 10, 7, y, GMP_RNDN); + printf (" + %.20g)\nexpected ", d); + mpfr_out_str (stdout, 10, 0, z, GMP_RNDN); + printf ("\ngot "); + mpfr_out_str (stdout, 10, 0, x, GMP_RNDN); + printf ("\n"); + exit (1); + } + mpfr_clears (x, y, z, (void *)0); + check_nans (); test_generic (2, 1000, 100); diff --git a/tests/tdiv_d.c b/tests/tdiv_d.c index de2ca21a4..5ca08da9a 100644 --- a/tests/tdiv_d.c +++ b/tests/tdiv_d.c @@ -68,9 +68,40 @@ check_nans (void) int main (int argc, char *argv[]) { + mpfr_t x, y, z; + double d; + int inexact; MPFR_TEST_USE_RANDS (); tests_start_mpfr (); + /* check with enough precision */ + mpfr_init2 (x, IEEE_DBL_MANT_DIG); + mpfr_init2 (y, IEEE_DBL_MANT_DIG); + mpfr_init2 (z, IEEE_DBL_MANT_DIG); + + mpfr_set_str (y, "4096", 10, GMP_RNDN); + d = 0.125; + mpfr_clear_flags (); + inexact = mpfr_div_d (x, y, d, GMP_RNDN); + if (inexact != 0) + { + printf ("Inexact flag error in mpfr_div_d\n"); + exit (1); + } + mpfr_set_str (z, "32768", 10, GMP_RNDN); + if (mpfr_cmp (z, x)) + { + printf ("Error in mpfr_div_d ("); + mpfr_out_str (stdout, 10, 0, y, GMP_RNDN); + printf (" + %.20g)\nexpected ", d); + mpfr_out_str (stdout, 10, 0, z, GMP_RNDN); + printf ("\ngot "); + mpfr_out_str (stdout, 10, 0, x, GMP_RNDN); + printf ("\n"); + exit (1); + } + mpfr_clears (x, y, z, (void *)0); + check_nans (); test_generic (2, 1000, 100); diff --git a/tests/tmul_d.c b/tests/tmul_d.c index 19e61953b..e524679fa 100644 --- a/tests/tmul_d.c +++ b/tests/tmul_d.c @@ -67,9 +67,40 @@ check_nans (void) int main (int argc, char *argv[]) { + mpfr_t x, y, z; + double d; + int inexact; MPFR_TEST_USE_RANDS (); tests_start_mpfr (); + /* check with enough precision */ + mpfr_init2 (x, IEEE_DBL_MANT_DIG); + mpfr_init2 (y, IEEE_DBL_MANT_DIG); + mpfr_init2 (z, IEEE_DBL_MANT_DIG); + + mpfr_set_str (y, "4096", 10, GMP_RNDN); + d = 0.125; + mpfr_clear_flags (); + inexact = mpfr_mul_d (x, y, d, GMP_RNDN); + if (inexact != 0) + { + printf ("Inexact flag error in mpfr_mul_d\n"); + exit (1); + } + mpfr_set_str (z, "512", 10, GMP_RNDN); + if (mpfr_cmp (z, x)) + { + printf ("Error in mpfr_mul_d ("); + mpfr_out_str (stdout, 10, 0, y, GMP_RNDN); + printf (" + %.20g)\nexpected ", d); + mpfr_out_str (stdout, 10, 0, z, GMP_RNDN); + printf ("\ngot "); + mpfr_out_str (stdout, 10, 0, x, GMP_RNDN); + printf ("\n"); + exit (1); + } + mpfr_clears (x, y, z, (void *)0); + check_nans (); test_generic (2, 1000, 100); diff --git a/tests/tsub_d.c b/tests/tsub_d.c index 2bfd4e194..983286a45 100644 --- a/tests/tsub_d.c +++ b/tests/tsub_d.c @@ -63,9 +63,40 @@ check_nans (void) int main (int argc, char *argv[]) { + mpfr_t x, y, z; + double d; + int inexact; MPFR_TEST_USE_RANDS (); tests_start_mpfr (); + /* check with enough precision */ + mpfr_init2 (x, IEEE_DBL_MANT_DIG); + mpfr_init2 (y, IEEE_DBL_MANT_DIG); + mpfr_init2 (z, IEEE_DBL_MANT_DIG); + + mpfr_set_str (y, "4096", 10, GMP_RNDN); + d = 0.125; + mpfr_clear_flags (); + inexact = mpfr_sub_d (x, y, d, GMP_RNDN); + if (inexact != 0) + { + printf ("Inexact flag error in mpfr_sub_d\n"); + exit (1); + } + mpfr_set_str (z, "4095.875", 10, GMP_RNDN); + if (mpfr_cmp (z, x)) + { + printf ("Error in mpfr_sub_d ("); + mpfr_out_str (stdout, 10, 7, y, GMP_RNDN); + printf (" + %.20g)\nexpected ", d); + mpfr_out_str (stdout, 10, 0, z, GMP_RNDN); + printf ("\ngot "); + mpfr_out_str (stdout, 10, 0, x, GMP_RNDN); + printf ("\n"); + exit (1); + } + mpfr_clears (x, y, z, (void *)0); + check_nans (); test_generic (2, 1000, 100); |