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/tadd_d.c | |
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/tadd_d.c')
-rw-r--r-- | tests/tadd_d.c | 62 |
1 files changed, 62 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); |