From c8bd900e284e5f5e323fbe644f2da5f149fe8546 Mon Sep 17 00:00:00 2001 From: zimmerma Date: Mon, 24 Oct 2011 10:31:52 +0000 Subject: fixed bug found by the automatic builds on http://hydra.nixos.org/build/1469029/log/raw git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@1102 211d60ee-9f03-0410-a15a-8952a2c7a4e4 --- src/pow.c | 16 ++++++++++++++-- tests/pow.dat | 5 +++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/pow.c b/src/pow.c index 37f7342..67059b5 100644 --- a/src/pow.c +++ b/src/pow.c @@ -165,7 +165,7 @@ fix_sign (mpc_ptr z, int sign_eps, int sign_a, mpfr_srcptr y) Assume one of Re(x) or Im(x) is non-zero, and y is non-zero (y is real). - Warning: z and x might be the same variable. + Warning: z and x might be the same variable, same for Re(z) or Im(z) and y. */ static int mpc_pow_exact (mpc_ptr z, mpc_srcptr x, mpfr_srcptr y, mpc_rnd_t rnd, @@ -178,6 +178,15 @@ mpc_pow_exact (mpc_ptr z, mpc_srcptr x, mpfr_srcptr y, mpc_rnd_t rnd, int sign_rex = mpfr_signbit (MPC_RE(x)); int sign_imx = mpfr_signbit (MPC_IM(x)); int x_imag = mpfr_zero_p (MPC_RE(x)); + int z_is_y = 0; + mpfr_t copy_of_y; + + if (mpc_realref (z) == y || mpc_imagref (z) == y) + { + z_is_y = 1; + mpfr_init2 (copy_of_y, mpfr_get_prec (y)); + mpfr_set (copy_of_y, y, GMP_RNDN); + } mpz_init (my); mpz_init (a); @@ -406,7 +415,10 @@ mpc_pow_exact (mpc_ptr z, mpc_srcptr x, mpfr_srcptr y, mpc_rnd_t rnd, mpz_clear (u); if (ret >= 0 && x_imag) - fix_sign (z, sign_rex, sign_imx, y); + fix_sign (z, sign_rex, sign_imx, (z_is_y) ? copy_of_y : y); + + if (z_is_y) + mpfr_clear (copy_of_y); return ret; } diff --git a/tests/pow.dat b/tests/pow.dat index b2073da..4e302f7 100644 --- a/tests/pow.dat +++ b/tests/pow.dat @@ -436,3 +436,8 @@ + + 2 -0 2 -0 2 3 2 -1 28 -744261116 2 +0 N N - + 2 +0 2 -0 2 4 2 3 28 -744261116 2 +0 N N - - 2 +0 2 +0 2 4 2 -3 28 -744261116 2 +0 N N + +# bug found by the automatic builds on +# http://hydra.nixos.org/build/1469029/log/raw (only happens for z = x^y when +# z and y are the same variable) +- 0 2 0x3p-5 2 -0 2 +0 2 0x3p-2 2 8 2 +0 N N -- cgit v1.2.1