summaryrefslogtreecommitdiff
path: root/tests/tget_f.c
diff options
context:
space:
mode:
authorthevenyp <thevenyp@280ebfd0-de03-0410-8827-d642c229c3f4>2009-04-14 14:34:20 +0000
committerthevenyp <thevenyp@280ebfd0-de03-0410-8827-d642c229c3f4>2009-04-14 14:34:20 +0000
commita3f7e0eef0782ca008a550fccb0ba0e10da582c7 (patch)
tree705fb5b15d1231f780becd71ccafdcc674e8cac5 /tests/tget_f.c
parent4a81a121a69aa31f6c43fcb0e0cb58fc28ce57e3 (diff)
downloadmpfr-a3f7e0eef0782ca008a550fccb0ba0e10da582c7.tar.gz
tests/tget_f.c get_f.c: Set result to the maximum value when the mpfr_t is plus infinity and set correct ternary value.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@6171 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tget_f.c')
-rw-r--r--tests/tget_f.c111
1 files changed, 69 insertions, 42 deletions
diff --git a/tests/tget_f.c b/tests/tget_f.c
index 70c9c1c4f..28b286fbb 100644
--- a/tests/tget_f.c
+++ b/tests/tget_f.c
@@ -99,6 +99,74 @@ prec_test (void)
}
static void
+special_test (void)
+{
+ int inex;
+ mpf_t x;
+ mpfr_t y;
+
+ mpfr_init (y);
+ mpf_init (x);
+
+ mpfr_set_nan (y);
+ mpfr_clear_flags ();
+ mpfr_get_f (x, y, MPFR_RNDN);
+ if (! mpfr_erangeflag_p ())
+ {
+ printf ("Error: mpfr_get_f(NaN) should raise erange flag\n");
+ exit (1);
+ }
+
+ mpfr_set_inf (y, +1);
+ mpfr_clear_flags ();
+ inex = mpfr_get_f (x, y, MPFR_RNDN);
+ if (inex >= 0)
+ {
+ printf ("Error: mpfr_get_f(+Inf) should return a negative ternary"
+ "value\n");
+ exit (1);
+ }
+ if (! mpfr_erangeflag_p ())
+ {
+ printf ("Error: mpfr_get_f(+Inf) should raise erange flag\n");
+ exit (1);
+ }
+
+ mpfr_set_inf (y, -1);
+ mpfr_clear_flags ();
+ inex = mpfr_get_f (x, y, MPFR_RNDN);
+ if (inex <= 0)
+ {
+ printf ("Error: mpfr_get_f(-Inf) should return a positive ternary"
+ "value\n");
+ exit (1);
+ }
+ if (! mpfr_erangeflag_p ())
+ {
+ printf ("Error: mpfr_get_f(-Inf) should raise erange flag\n");
+ exit (1);
+ }
+
+ mpfr_set_ui (y, 0, MPFR_RNDN);
+ if (mpfr_get_f (x, y, MPFR_RNDN) != 0 || mpf_cmp_ui (x, 0))
+ {
+ printf ("Error: mpfr_get_f(+0) fails\n");
+ exit (1);
+ }
+
+ mpfr_set_ui (y, 0, MPFR_RNDN);
+ mpfr_neg (y, y, MPFR_RNDN);
+ if (mpfr_get_f (x, y, MPFR_RNDN) != 0 || mpf_cmp_ui (x, 0))
+ {
+ printf ("Error: mpfr_get_f(-0) fails\n");
+ exit (1);
+ }
+
+ mpfr_clear (y);
+ mpf_clear (x);
+}
+
+static void
ternary_test (void)
{
int inex;
@@ -211,48 +279,6 @@ main (void)
mpfr_init (z);
mpf_init (x);
- mpfr_set_nan (y);
- mpfr_clear_flags ();
- mpfr_get_f (x, y, MPFR_RNDN);
- if (!mpfr_erangeflag_p())
- {
- printf ("Error: mpfr_get_f(NaN) should raise erange flag\n");
- exit (1);
- }
-
- mpfr_set_inf (y, 1);
- mpfr_clear_flags ();
- mpfr_get_f (x, y, MPFR_RNDN);
- if (!mpfr_erangeflag_p())
- {
- printf ("Error: mpfr_get_f(+Inf) should raise erange flag\n");
- exit (1);
- }
-
- mpfr_set_inf (y, -1);
- mpfr_clear_flags ();
- mpfr_get_f (x, y, MPFR_RNDN);
- if (!mpfr_erangeflag_p())
- {
- printf ("Error: mpfr_get_f(-Inf) should raise erange flag\n");
- exit (1);
- }
-
- mpfr_set_ui (y, 0, MPFR_RNDN);
- if (mpfr_get_f (x, y, MPFR_RNDN) != 0 || mpf_cmp_ui (x, 0))
- {
- printf ("Error: mpfr_get_f(+0) fails\n");
- exit (1);
- }
-
- mpfr_set_ui (y, 0, MPFR_RNDN);
- mpfr_neg (y, y, MPFR_RNDN);
- if (mpfr_get_f (x, y, MPFR_RNDN) != 0 || mpf_cmp_ui (x, 0))
- {
- printf ("Error: mpfr_get_f(-0) fails\n");
- exit (1);
- }
-
i = 1;
while (i)
{
@@ -355,6 +381,7 @@ main (void)
mpfr_clear (z);
mpf_clear (x);
+ special_test ();
prec_test ();
ternary_test ();