summaryrefslogtreecommitdiff
path: root/tests/tsubnormal.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2018-07-21 00:55:29 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2018-07-21 00:55:29 +0000
commitba61e5208631026b0cb90c540abf9dfad15cc0ce (patch)
tree8ad1df06a289680eee2586c5eb7766ca41587b2a /tests/tsubnormal.c
parent43aba257b9a0b97fbfb1acf2a00f3df3e5b05973 (diff)
downloadmpfr-ba61e5208631026b0cb90c540abf9dfad15cc0ce.tar.gz
[src/subnormal.c] experimental support for RNDNA
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@12944 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tsubnormal.c')
-rw-r--r--tests/tsubnormal.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/tsubnormal.c b/tests/tsubnormal.c
index 555acb548..1d8de50ff 100644
--- a/tests/tsubnormal.c
+++ b/tests/tsubnormal.c
@@ -204,11 +204,57 @@ check3 (void)
set_emin (emin);
}
+/* check mpfr_subnormize with RNDNA (experimental) */
+static void
+check_rndna (void)
+{
+ mpfr_t x, y;
+ int inex;
+ mpfr_exp_t emin = mpfr_get_emin ();
+
+ mpfr_init2 (x, 11);
+ mpfr_init2 (y, 9);
+
+ mpfr_set_str_binary (x, "0.1111111010E-14");
+ inex = mpfr_set (y, x, MPFR_RNDN);
+ MPFR_ASSERTN(inex == 0);
+ mpfr_set_emin (-21);
+ inex = mpfr_subnormalize (y, inex, MPFR_RNDNA);
+ /* mpfr_subnormalize rounds to precision EXP(y)-emin+1 = 8,
+ thus should round to 0.111111110E-14 */
+ mpfr_set_str_binary (x, "0.111111110E-14");
+ MPFR_ASSERTN(mpfr_cmp (y, x) == 0);
+ MPFR_ASSERTN(inex > 0);
+
+ /* now consider x slightly larger: we should get the same result */
+ mpfr_set_str_binary (x, "0.1111111011E-14");
+ inex = mpfr_set (y, x, MPFR_RNDN);
+ MPFR_ASSERTN(inex > 0);
+ inex = mpfr_subnormalize (y, inex, MPFR_RNDNA);
+ mpfr_set_str_binary (x, "0.111111110E-14");
+ MPFR_ASSERTN(mpfr_cmp (y, x) == 0);
+ MPFR_ASSERTN(inex > 0);
+
+ /* now consider x slightly smaller: we should get a different result */
+ mpfr_set_str_binary (x, "0.11111110001E-14");
+ inex = mpfr_set (y, x, MPFR_RNDN);
+ MPFR_ASSERTN(inex < 0);
+ inex = mpfr_subnormalize (y, inex, MPFR_RNDNA);
+ mpfr_set_str_binary (x, "0.111111100E-14");
+ MPFR_ASSERTN(mpfr_cmp (y, x) == 0);
+ MPFR_ASSERTN(inex < 0);
+
+ mpfr_clear (x);
+ mpfr_clear (y);
+ mpfr_set_emin (emin);
+}
+
int
main (int argc, char *argv[])
{
tests_start_mpfr ();
+ check_rndna ();
check1 ();
check2 ();
check3 ();