summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-06-07 21:54:01 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-06-07 21:54:01 +0000
commitd708627d6959f296c30362db15b72e830397c82c (patch)
tree85689b5deabbbccce1650804bb9e9865f576f68a
parentcb809ea1cb721e03b022a223db55326a27967e7b (diff)
downloadmpfr-d708627d6959f296c30362db15b72e830397c82c.tar.gz
[src/zeta_ui.c] Fixed zeta(0) in reduced exponent range.
[tests/tzeta_ui.c] Added testcase. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9518 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/zeta_ui.c5
-rw-r--r--tests/tzeta_ui.c58
2 files changed, 56 insertions, 7 deletions
diff --git a/src/zeta_ui.c b/src/zeta_ui.c
index c8155936b..7bd9736cd 100644
--- a/src/zeta_ui.c
+++ b/src/zeta_ui.c
@@ -30,10 +30,7 @@ mpfr_zeta_ui (mpfr_ptr z, unsigned long m, mpfr_rnd_t r)
if (m == 0)
{
- mpfr_set_ui (z, 1, r);
- mpfr_div_2ui (z, z, 1, r);
- MPFR_CHANGE_SIGN (z);
- MPFR_RET (0);
+ return mpfr_set_si_2exp (z, -1, -1, r);
}
else if (m == 1)
{
diff --git a/tests/tzeta_ui.c b/tests/tzeta_ui.c
index fbbbf287e..589227c97 100644
--- a/tests/tzeta_ui.c
+++ b/tests/tzeta_ui.c
@@ -33,9 +33,15 @@ main (int argc, char *argv[])
mpfr_t x, y, z, t;
unsigned long n;
int inex;
+ mpfr_exp_t emin, emax;
+ mpfr_flags_t flags, ex_flags;
+ int i;
tests_start_mpfr ();
+ emin = mpfr_get_emin ();
+ emax = mpfr_get_emax ();
+
mpfr_init (x);
mpfr_init (y);
mpfr_init (z);
@@ -63,10 +69,56 @@ main (int argc, char *argv[])
exit (1);
}
- mpfr_clear_divby0 ();
+ mpfr_clear_flags ();
inex = mpfr_zeta_ui (x, 0, MPFR_RNDN);
- MPFR_ASSERTN (inex == 0 && mpfr_cmp_si_2exp (x, -1, -1) == 0
- && !mpfr_divby0_p ());
+ flags = __gmpfr_flags;
+ MPFR_ASSERTN (inex == 0 && mpfr_cmp_si_2exp (x, -1, -1) == 0 && flags == 0);
+
+ for (i = -2; i <= 2; i += 2)
+ {
+ int ex_inex, err;
+ char *s;
+
+ set_emin (i);
+ set_emax (i);
+ mpfr_clear_flags ();
+ inex = mpfr_zeta_ui (x, 0, MPFR_RNDN);
+ flags = __gmpfr_flags;
+ set_emin (emin);
+ set_emax (emax);
+ if (i < 0)
+ {
+ s = "-@Inf@";
+ ex_inex = -1;
+ ex_flags = MPFR_FLAGS_OVERFLOW | MPFR_FLAGS_INEXACT;
+ err = !(mpfr_inf_p (x) && MPFR_IS_NEG (x));
+ }
+ else if (i > 0)
+ {
+ s = "-0";
+ ex_inex = 1;
+ ex_flags = MPFR_FLAGS_UNDERFLOW | MPFR_FLAGS_INEXACT;
+ err = !(mpfr_zero_p (x) && MPFR_IS_NEG (x));
+ }
+ else
+ {
+ s = "-1/2";
+ ex_inex = 0;
+ ex_flags = 0;
+ err = mpfr_cmp_si_2exp (x, -1, -1) != 0;
+ }
+ if (err || ! SAME_SIGN (inex, ex_inex) || flags != ex_flags)
+ {
+ printf ("Failure for zeta(0) in exponent range [%d,%d]\n", i, i);
+ printf ("Expected %s, sign(inex) = %d, flags =", s, ex_inex);
+ flags_out (ex_flags);
+ printf ("Got ");
+ mpfr_dump (x);
+ printf ("with inex = %d, flags =", inex);
+ flags_out (flags);
+ exit (1);
+ }
+ }
mpfr_clear_divby0 ();
inex = mpfr_zeta_ui (x, 1, MPFR_RNDN);