summaryrefslogtreecommitdiff
path: root/src/sqr.c
diff options
context:
space:
mode:
authorPaul Zimmermann <paul.zimmermann@inria.fr>2008-11-15 09:52:35 +0000
committerPaul Zimmermann <paul.zimmermann@inria.fr>2008-11-15 09:52:35 +0000
commitcff3574f61fdd4635eaf09a5f94f4de504c48fb3 (patch)
tree73db82b6ad5d3fae16cded7277d99444b08be3f8 /src/sqr.c
parentb39b42f6f5b280ddd82931ad5c45d61dce4bfb17 (diff)
downloadmpc-git-cff3574f61fdd4635eaf09a5f94f4de504c48fb3.tar.gz
[sqr.c] simplified code as for mul_karatsuba
[tan.c] re-enabled apparently dead code, until we prove it is really dead git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/mpc/trunk@318 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'src/sqr.c')
-rw-r--r--src/sqr.c74
1 files changed, 30 insertions, 44 deletions
diff --git a/src/sqr.c b/src/sqr.c
index c8cf4fb..210e5f0 100644
--- a/src/sqr.c
+++ b/src/sqr.c
@@ -156,52 +156,38 @@ mpc_sqr (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
/* compute the real part as u*v, rounded away */
/* determine also the sign of inex_re */
if (mpfr_sgn (u) == 0 || mpfr_sgn (v) == 0)
- {
- /* as we have rounded away, the result is exact */
- mpfr_set_ui (u, 0, GMP_RNDN);
- mpfr_set_ui (MPC_RE (rop), 0, GMP_RNDN);
- inex_re = 0;
- ok = 1;
- }
+ {
+ /* as we have rounded away, the result is exact */
+ mpfr_set_ui (u, 0, GMP_RNDN);
+ mpfr_set_ui (MPC_RE (rop), 0, GMP_RNDN);
+ inex_re = 0;
+ ok = 1;
+ }
else if (mpfr_sgn (u) * mpfr_sgn (v) > 0)
- {
- inexact |= mpfr_mul (u, u, v, GMP_RNDU); /* error 5 */
- ok = !inexact | mpfr_can_round (u, prec - 3, GMP_RNDU,
- MPC_RND_RE (rnd), MPFR_PREC (MPC_RE (rop)));
- if (ok)
- {
- inex_re = mpfr_set (MPC_RE (rop), u, MPC_RND_RE (rnd));
- if (inex_re == 0)
- /* remember that u was already rounded */
- inex_re = inexact;
- /* even if rounding did work, we might not know whether the
- result is too large, too small or exact */
- else if (inexact && MPC_RND_RE (rnd) == GMP_RNDN
- && inex_re < 0
- && !mpfr_can_round (u, prec - 3, GMP_RNDU, GMP_RNDU,
- MPFR_PREC (MPC_RE (rop))))
- ok = 0;
- }
- }
+ {
+ inexact |= mpfr_mul (u, u, v, GMP_RNDU); /* error 5 */
+ ok = !inexact | mpfr_can_round (u, prec - 3, GMP_RNDU, GMP_RNDZ,
+ MPFR_PREC (MPC_RE (rop)) + (MPC_RND_RE (rnd) == GMP_RNDN));
+ if (ok)
+ {
+ inex_re = mpfr_set (MPC_RE (rop), u, MPC_RND_RE (rnd));
+ if (inex_re == 0)
+ /* remember that u was already rounded */
+ inex_re = inexact;
+ }
+ }
else
- {
- inexact |= mpfr_mul (u, u, v, GMP_RNDD); /* error 5 */
- ok = !inexact | mpfr_can_round (u, prec - 3, GMP_RNDD,
- MPC_RND_RE (rnd), MPFR_PREC (MPC_RE (rop)));
- if (ok)
- {
- inex_re = mpfr_set (MPC_RE (rop), u, MPC_RND_RE (rnd));
- if (inex_re == 0)
- inex_re = inexact;
- /* even if rounding did work, we might not know whether the
- result is too large, too small or exact */
- else if (inexact && MPC_RND_RE (rnd) == GMP_RNDN
- && inex_re > 0
- && !mpfr_can_round (u, prec - 3, GMP_RNDD, GMP_RNDD,
- MPFR_PREC (MPC_RE (rop))))
- ok = 0;
- }
- }
+ {
+ inexact |= mpfr_mul (u, u, v, GMP_RNDD); /* error 5 */
+ ok = !inexact | mpfr_can_round (u, prec - 3, GMP_RNDD, GMP_RNDZ,
+ MPFR_PREC (MPC_RE (rop)) + (MPC_RND_RE (rnd) == GMP_RNDN));
+ if (ok)
+ {
+ inex_re = mpfr_set (MPC_RE (rop), u, MPC_RND_RE (rnd));
+ if (inex_re == 0)
+ inex_re = inexact;
+ }
+ }
}
while (!ok);