diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-11-10 13:13:13 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-11-10 13:13:13 +0000 |
commit | 1315110b7065c2d08e69fca23b5984c483acfa45 (patch) | |
tree | 866f69b874d527b5fa210e77a740d92c3f719f1f /tests/tabs.c | |
parent | 0bb0af6e187aa8bbff11d8ba5a581b029a63cfe3 (diff) | |
download | mpfr-1315110b7065c2d08e69fca23b5984c483acfa45.tar.gz |
[tests/tabs.c] More tests on mpfr_abs, including the ternary value
and the NaN flag and sign bit for ±NaN.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@11818 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tabs.c')
-rw-r--r-- | tests/tabs.c | 162 |
1 files changed, 122 insertions, 40 deletions
diff --git a/tests/tabs.c b/tests/tabs.c index b1c18d8f5..b24854e13 100644 --- a/tests/tabs.c +++ b/tests/tabs.c @@ -80,55 +80,137 @@ static void check_cmp (int argc, char *argv[]) { mpfr_t x, y; + mpfr_ptr p[2]; + int inexact; int n, k; mpfr_inits2 (53, x, y, (mpfr_ptr) 0); - mpfr_set_ui (x, 1, MPFR_RNDN); - (mpfr_abs) (x, x, MPFR_RNDN); - if (mpfr_cmp_ui (x, 1)) - { - printf ("Error in mpfr_abs(1.0)\n"); - exit (1); - } + /* will test with DEST != SRC and with DEST == SRC */ + p[0] = y; /* y first */ + p[1] = x; /* x last since it may be modified */ - mpfr_set_si (x, -1, MPFR_RNDN); - mpfr_abs (x, x, MPFR_RNDN); - if (mpfr_cmp_ui (x, 1)) + for (k = 0; k <= 1; k++) { - printf ("Error in mpfr_abs(1.0)\n"); - exit (1); - } + mpfr_set_nan (p[k]); + mpfr_set_ui (x, 1, MPFR_RNDN); + inexact = mpfr_abs (p[k], x, MPFR_RNDN); + if (mpfr_cmp_ui (p[k], 1) || inexact != 0) + { + printf ("Error in mpfr_abs(1.0) for k = %d\n", k); + exit (1); + } - mpfr_set_si (x, -1, MPFR_RNDN); - mpfr_abs (x, x, MPFR_RNDN); - if (mpfr_cmp_ui (x, 1)) - { - printf ("Error in mpfr_abs(-1.0)\n"); - exit (1); - } + mpfr_set_nan (p[k]); + mpfr_set_ui (x, 1, MPFR_RNDN); + inexact = (mpfr_abs) (p[k], x, MPFR_RNDN); + if (mpfr_cmp_ui (p[k], 1) || inexact != 0) + { + printf ("Error in (mpfr_abs)(1.0) for k = %d\n", k); + exit (1); + } - mpfr_set_inf (x, 1); - mpfr_abs (x, x, MPFR_RNDN); - if (!mpfr_inf_p(x) || (mpfr_sgn(x) <= 0)) - { - printf ("Error in mpfr_abs(Inf).\n"); - exit (1); - } - mpfr_set_inf (x, -1); - mpfr_abs (x, x, MPFR_RNDN); - if (!mpfr_inf_p(x) || (mpfr_sgn(x) <= 0)) - { - printf ("Error in mpfr_abs(-Inf).\n"); - exit (1); - } + mpfr_set_nan (p[k]); + mpfr_set_si (x, -1, MPFR_RNDN); + inexact = mpfr_abs (p[k], x, MPFR_RNDN); + if (mpfr_cmp_ui (p[k], 1) || inexact != 0) + { + printf ("Error in mpfr_abs(-1.0) for k = %d\n", k); + exit (1); + } - MPFR_SET_NAN(x); - mpfr_abs (x, x, MPFR_RNDN); - if (!MPFR_IS_NAN(x)) - { - printf ("Error in mpfr_abs(NAN).\n"); - exit (1); + mpfr_set_nan (p[k]); + mpfr_set_si (x, -1, MPFR_RNDN); + inexact = (mpfr_abs) (p[k], x, MPFR_RNDN); + if (mpfr_cmp_ui (p[k], 1) || inexact != 0) + { + printf ("Error in (mpfr_abs)(-1.0) for k = %d\n", k); + exit (1); + } + + mpfr_set_nan (p[k]); + mpfr_set_inf (x, 1); + inexact = mpfr_abs (p[k], x, MPFR_RNDN); + if (! mpfr_inf_p (p[k]) || mpfr_sgn (p[k]) <= 0 || inexact != 0) + { + printf ("Error in mpfr_abs(Inf) for k = %d\n", k); + exit (1); + } + + mpfr_set_nan (p[k]); + mpfr_set_inf (x, 1); + inexact = (mpfr_abs) (p[k], x, MPFR_RNDN); + if (! mpfr_inf_p (p[k]) || mpfr_sgn (p[k]) <= 0 || inexact != 0) + { + printf ("Error in (mpfr_abs)(Inf) for k = %d\n", k); + exit (1); + } + + mpfr_set_nan (p[k]); + mpfr_set_inf (x, -1); + inexact = mpfr_abs (p[k], x, MPFR_RNDN); + if (! mpfr_inf_p (p[k]) || mpfr_sgn (p[k]) <= 0 || inexact != 0) + { + printf ("Error in mpfr_abs(-Inf) for k = %d\n", k); + exit (1); + } + + mpfr_set_nan (p[k]); + mpfr_set_inf (x, -1); + inexact = (mpfr_abs) (p[k], x, MPFR_RNDN); + if (! mpfr_inf_p (p[k]) || mpfr_sgn (p[k]) <= 0 || inexact != 0) + { + printf ("Error in (mpfr_abs)(-Inf) for k = %d\n", k); + exit (1); + } + + mpfr_set_zero (p[k], 1); + MPFR_SET_NAN (x); + MPFR_SET_POS (x); + mpfr_clear_nanflag (); + inexact = mpfr_abs (p[k], x, MPFR_RNDN); + if (! MPFR_IS_NAN (p[k]) || ! mpfr_nanflag_p () || + mpfr_signbit (p[k]) || inexact != 0) + { + printf ("Error in mpfr_abs(+NaN).\n"); + exit (1); + } + + mpfr_set_zero (p[k], 1); + MPFR_SET_NAN (x); + MPFR_SET_POS (x); + mpfr_clear_nanflag (); + inexact = (mpfr_abs) (p[k], x, MPFR_RNDN); + if (! MPFR_IS_NAN (p[k]) || ! mpfr_nanflag_p () || + mpfr_signbit (p[k]) || inexact != 0) + { + printf ("Error in (mpfr_abs)(+NaN).\n"); + exit (1); + } + + mpfr_set_zero (p[k], 1); + MPFR_SET_NAN (x); + MPFR_SET_NEG (x); + mpfr_clear_nanflag (); + inexact = mpfr_abs (p[k], x, MPFR_RNDN); + if (! MPFR_IS_NAN (p[k]) || ! mpfr_nanflag_p () || + mpfr_signbit (p[k]) || inexact != 0) + { + printf ("Error in mpfr_abs(-NaN).\n"); + exit (1); + } + + mpfr_set_zero (p[k], 1); + MPFR_SET_NAN (x); + MPFR_SET_NEG (x); + mpfr_clear_nanflag (); + inexact = (mpfr_abs) (p[k], x, MPFR_RNDN); + if (! MPFR_IS_NAN (p[k]) || ! mpfr_nanflag_p () || + mpfr_signbit (p[k]) || inexact != 0) + { + printf ("Error in (mpfr_abs)(-NaN).\n"); + exit (1); + } } n = (argc==1) ? 25000 : atoi(argv[1]); |