summaryrefslogtreecommitdiff
path: root/tests/tsqrt.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2016-09-08 14:22:04 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2016-09-08 14:22:04 +0000
commit0a92be75872d1d7471ebcf38a9c8d01c0456e63b (patch)
tree6c8a2a3f798c607babd88cce1fc17f7764fdd12f /tests/tsqrt.c
parent965748f7409821ba2dbc7611f2205ab6af1e6e74 (diff)
downloadmpfr-0a92be75872d1d7471ebcf38a9c8d01c0456e63b.tar.gz
[src/sqrt.c] fixed bug in mpfr_sqrt2
[tests/tsqrt.c] added non-regression test git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@10824 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tsqrt.c')
-rw-r--r--tests/tsqrt.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/tsqrt.c b/tests/tsqrt.c
index a4dea413c..6fbdc912a 100644
--- a/tests/tsqrt.c
+++ b/tests/tsqrt.c
@@ -597,6 +597,25 @@ bug20160120 (void)
mpfr_clear(y);
}
+/* Bug in mpfr_sqrt2 when prec(u) = 2*GMP_NUMB_BITS and the exponent of u is
+ odd: the last bit of u is lost. */
+static void
+bug20160908 (void)
+{
+ mpfr_t r, u;
+ int n = GMP_NUMB_BITS, ret;
+
+ mpfr_init2 (r, 2*n - 1);
+ mpfr_init2 (u, 2 * n);
+ mpfr_set_ui_2exp (u, 1, 2*n-2, MPFR_RNDN); /* u=2^(2n-2) with exp(u)=2n-1 */
+ mpfr_nextabove (u);
+ /* now u = 2^(2n-2) + 1/2 */
+ ret = mpfr_sqrt (r, u, MPFR_RNDZ);
+ MPFR_ASSERTN(ret == -1 && mpfr_cmp_ui_2exp (r, 1, n-1) == 0);
+ mpfr_clear (r);
+ mpfr_clear (u);
+}
+
#define TEST_FUNCTION test_sqrt
#define TEST_RANDOM_POS 8
#include "tgeneric.c"
@@ -733,6 +752,7 @@ main (void)
bad_cases (mpfr_sqrt, mpfr_sqr, "mpfr_sqrt", 8, -256, 255, 4, 128, 800, 50);
bug20160120 ();
+ bug20160908 ();
tests_end_mpfr ();
return 0;