diff options
author | Paul Zimmermann <Paul.Zimmermann@inria.fr> | 2015-04-11 17:09:47 +0200 |
---|---|---|
committer | Paul Zimmermann <Paul.Zimmermann@inria.fr> | 2015-04-11 17:09:47 +0200 |
commit | 3c8cc49f1f3b702622cc87488ee3f3c897c29c58 (patch) | |
tree | 399ffc5c4758dd9eaceee078f01a2c610e33a4df | |
parent | d1340c375eac34de1268ee60e2eeb5ddf3b18531 (diff) | |
download | mpc-git-3c8cc49f1f3b702622cc87488ee3f3c897c29c58.tar.gz |
fixed bug reported by Joseph Myers
(http://lists.gforge.inria.fr/pipermail/mpc-discuss/2015-April/001342.html)
-rw-r--r-- | src/exp.c | 20 | ||||
-rw-r--r-- | tests/exceptions.c | 7 |
2 files changed, 16 insertions, 11 deletions
@@ -178,16 +178,16 @@ mpc_exp (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) inex_re = mpfr_set (mpc_realref(rop), y, MPC_RND_RE(rnd)); inex_im = mpfr_set (mpc_imagref(rop), z, MPC_RND_IM(rnd)); - if (mpfr_overflow_p ()) { - /* overflow in real exponential, inex is sign of infinite result */ - inex_re = mpc_fix_inf (mpc_realref(rop), MPC_RND_RE(rnd)); - inex_im = mpc_fix_inf (mpc_imagref(rop), MPC_RND_IM(rnd)); - } - else if (mpfr_underflow_p ()) { - /* underflow in real exponential, inex is opposite of sign of 0 result */ - inex_re = (mpfr_signbit (y) ? +1 : -1); - inex_im = (mpfr_signbit (z) ? +1 : -1); - } + if (mpfr_overflow_p ()) + { + inex_re = mpc_fix_inf (mpc_realref(rop), MPC_RND_RE(rnd)); + inex_im = mpc_fix_inf (mpc_imagref(rop), MPC_RND_IM(rnd)); + } + else if (mpfr_underflow_p ()) + { + inex_re = mpc_fix_zero (mpc_realref(rop), MPC_RND_RE(rnd)); + inex_im = mpc_fix_zero (mpc_imagref(rop), MPC_RND_IM(rnd)); + } mpfr_clear (x); mpfr_clear (y); diff --git a/tests/exceptions.c b/tests/exceptions.c index c37a773..257cc65 100644 --- a/tests/exceptions.c +++ b/tests/exceptions.c @@ -34,20 +34,25 @@ foo (int f(mpc_ptr, mpc_srcptr, mpc_rnd_t), char *s) #define N 5 mpfr_exp_t exy[N][2] = {{200, 800}, {800, 200}, {-50, 50}, {-10, 1000}, {0, 1000}}; - int n, inex, inex_re, inex_im; + int n, inex, inex_re, inex_im, sgn; mpc_init2 (z, MPFR_PREC_MIN); mpc_init2 (t, MPFR_PREC_MIN); for (n = 0; n < N; n++) + for (sgn = 0; sgn < 4; sgn++) { if (exy[n][0]) mpfr_set_ui_2exp (mpc_realref (z), 1, exy[n][0], MPFR_RNDN); else mpfr_set_ui (mpc_realref (z), 0, MPFR_RNDN); + if (sgn & 1) + mpfr_neg (mpc_realref (z), mpc_realref (z), MPFR_RNDN); if (exy[n][1]) mpfr_set_ui_2exp (mpc_imagref (z), 1, exy[n][1], MPFR_RNDN); else mpfr_set_ui (mpc_imagref (z), 0, MPFR_RNDN); + if (sgn & 2) + mpfr_neg (mpc_imagref (z), mpc_imagref (z), MPFR_RNDN); inex = f (t, z, MPC_RNDZZ); inex_re = MPC_INEX_RE(inex); |