summaryrefslogtreecommitdiff
path: root/tests/tsub1sp.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2016-07-04 10:36:16 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2016-07-04 10:36:16 +0000
commitd6bea42085020ed18946b7064df3db2ac6a6eea6 (patch)
treef19ecc684aede61a21e31c46daa3b4c5efcc0c0c /tests/tsub1sp.c
parented4074c6c69c0f1e45c1c14eb66935fd1a5700ea (diff)
downloadmpfr-d6bea42085020ed18946b7064df3db2ac6a6eea6.tar.gz
speedup of mpfr_sub for same precision < GMP_NUMB_BITS
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@10539 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tsub1sp.c')
-rw-r--r--tests/tsub1sp.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/tsub1sp.c b/tests/tsub1sp.c
index b191e350f..03c6723aa 100644
--- a/tests/tsub1sp.c
+++ b/tests/tsub1sp.c
@@ -24,6 +24,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
static void check_special (void);
static void check_random (mpfr_prec_t p);
+static void check_underflow (mpfr_prec_t p);
int
main (void)
@@ -32,6 +33,8 @@ main (void)
tests_start_mpfr ();
+ for (p = MPFR_PREC_MIN; p < 200 ; p++)
+ check_underflow (p);
check_special ();
for (p = MPFR_PREC_MIN ; p < 200 ; p++)
check_random (p);
@@ -49,7 +52,7 @@ main (void)
printf ("Z="); mpfr_dump (z); \
printf ("Real: "); mpfr_dump (x2); \
printf ("Got : "); mpfr_dump (x); \
- exit(1); \
+ abort(); \
} \
while (0)
@@ -509,3 +512,44 @@ check_special (void)
mpfr_clears (x, y, z, x2, (mpfr_ptr) 0);
}
+
+static void
+check_underflow (mpfr_prec_t p)
+{
+ mpfr_t x, y, z;
+ int inexact;
+
+ mpfr_inits2 (p, x, y, z, (mpfr_ptr) 0);
+
+ if (p >= 2) /* we need p >= 2 so that 3 is exact */
+ {
+ mpfr_set_ui_2exp (y, 4, mpfr_get_emin () - 2, MPFR_RNDN);
+ mpfr_set_ui_2exp (z, 3, mpfr_get_emin () - 2, MPFR_RNDN);
+ inexact = mpfr_sub (x, y, z, MPFR_RNDN);
+ if (inexact >= 0 || (mpfr_cmp_ui (x, 0) != 0))
+ {
+ printf ("4*2^(emin-2) - 3*2^(emin-2) with RNDN failed for p=%lu\n", p);
+ printf ("Expected inexact < 0 with x=0\n");
+ printf ("Got inexact=%d with x=");
+ mpfr_dump (x);
+ exit (1);
+ }
+ }
+
+ if (p >= 3) /* we need p >= 3 so that 5 is exact */
+ {
+ mpfr_set_ui_2exp (y, 5, mpfr_get_emin () - 2, MPFR_RNDN);
+ mpfr_set_ui_2exp (z, 4, mpfr_get_emin () - 2, MPFR_RNDN);
+ inexact = mpfr_sub (x, y, z, MPFR_RNDN);
+ if (inexact >= 0 || (mpfr_cmp_ui (x, 0) != 0))
+ {
+ printf ("5*2^(emin-2) - 4*2^(emin-2) with RNDN failed for p=%lu\n", p);
+ printf ("Expected inexact < 0 with x=0\n");
+ printf ("Got inexact=%d with x=");
+ mpfr_dump (x);
+ exit (1);
+ }
+ }
+
+ mpfr_clears (x, y, z, (mpfr_ptr) 0);
+}