summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/jyn_asympt.c10
-rw-r--r--tests/tj1.c22
2 files changed, 27 insertions, 5 deletions
diff --git a/src/jyn_asympt.c b/src/jyn_asympt.c
index e1c0e8ba6..7a28fa0bc 100644
--- a/src/jyn_asympt.c
+++ b/src/jyn_asympt.c
@@ -69,7 +69,7 @@ FUNCTION (mpfr_ptr res, long n, mpfr_srcptr z, mpfr_rnd_t r)
MPFR_ZIV_INIT (loop, w);
for (;;)
{
- int ok = 1;
+ int ok = 0;
mpfr_set_prec (c, w);
mpfr_init2 (s, w);
@@ -96,10 +96,7 @@ FUNCTION (mpfr_ptr res, long n, mpfr_srcptr z, mpfr_rnd_t r)
/* if s or c is zero, MPFR_GET_EXP will fail below */
if (MPFR_IS_ZERO(s) || MPFR_IS_ZERO(c))
- {
- ok = 0;
- goto clear;
- }
+ goto clear; /* with ok=0 */
/* precompute 1/(8|z|) */
mpfr_si_div (iz, MPFR_IS_POS(z) ? 1 : -1, z, MPFR_RNDN); /* err <= 1 */
@@ -227,6 +224,9 @@ FUNCTION (mpfr_ptr res, long n, mpfr_srcptr z, mpfr_rnd_t r)
mpfr_sub (s, c, s, MPFR_RNDN);
#endif
}
+ if (MPFR_IS_ZERO(s))
+ goto clear; /* with ok=0 */
+ ok = 1;
if ((n & 2) != 0)
mpfr_neg (s, s, MPFR_RNDN);
if (MPFR_GET_EXP (s) > err)
diff --git a/tests/tj1.c b/tests/tj1.c
index eeb722eee..0a2709143 100644
--- a/tests/tj1.c
+++ b/tests/tj1.c
@@ -72,6 +72,26 @@ test_small (void)
mpfr_clear (y);
}
+/* a test that fails with GMP_CHECK_RANDOMIZE=1613146232984428
+ on revision 14429 */
+static void
+bug20210215 (void)
+{
+ mpfr_t x, y;
+ int inex;
+
+ mpfr_init2 (x, 221);
+ mpfr_init2 (y, 1);
+ mpfr_set_str (x, "1.6484611511696130037307738844228498447763863563070374544054791168614e+01", 10, MPFR_RNDN);
+ mpfr_clear_flags ();
+ inex = mpfr_j1 (y, x, MPFR_RNDZ);
+ MPFR_ASSERTN (mpfr_cmp_si_2exp (y, -1, -9) == 0);
+ MPFR_ASSERTN (inex > 0);
+ MPFR_ASSERTN (__gmpfr_flags == MPFR_FLAGS_INEXACT);
+ mpfr_clear (x);
+ mpfr_clear (y);
+}
+
int
main (int argc, char *argv[])
{
@@ -79,6 +99,8 @@ main (int argc, char *argv[])
tests_start_mpfr ();
+ bug20210215 ();
+
test_small ();
mpfr_init (x);