summaryrefslogtreecommitdiff
path: root/src/mul.c
diff options
context:
space:
mode:
authorenge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2010-09-16 17:56:07 +0000
committerenge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2010-09-16 17:56:07 +0000
commitf648ef81fe9512b8a676c37b1ee19709c6be386b (patch)
tree9be3248c97723562fab2aa0b8284e35461823385 /src/mul.c
parentbc398ccb24bf53aeed593af3b86e1c4ead3d748f (diff)
downloadmpc-f648ef81fe9512b8a676c37b1ee19709c6be386b.tar.gz
mul.c, mul.dat: if both arguments are the same, call sqr
prevents infinite loops already fixed in sqr and as yet unknown bugs and assures the same behaviour as sqr in corner cases (overflow etc.) git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@833 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'src/mul.c')
-rw-r--r--src/mul.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/mul.c b/src/mul.c
index 5cd5bb8..0de9328 100644
--- a/src/mul.c
+++ b/src/mul.c
@@ -109,6 +109,12 @@ mpc_mul (mpc_ptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rnd)
/* note that a cannot be a zero */
return mul_pure_imaginary (a, b, MPC_IM (c), rnd, (a == b || a == c));
+ /* Check if b==c and call mpc_sqr in this case, to make sure */
+ /* mpc_mul(a,b,b) behaves exactly like mpc_sqr(a,b) concerning */
+ /* internal overflows etc. */
+ if (mpc_cmp (b, c) == 0)
+ return mpc_sqr (a, b, rnd);
+
/* If the real and imaginary part of one argument have a very different */
/* exponent, it is not reasonable to use Karatsuba multiplication. */
if ( SAFE_ABS (mpfr_exp_t,