summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorenge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2009-06-04 16:35:44 +0000
committerenge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2009-06-04 16:35:44 +0000
commit5e0c14ae8c276b91ff571003c3fd448beeb2fa3e (patch)
treed417524c632b4c75dfcab617f45c88d44226ddfa
parentb4e2005a89669ca9ffadfa7191ae7adcefe19824 (diff)
downloadmpc-5e0c14ae8c276b91ff571003c3fd448beeb2fa3e.tar.gz
fixed norm computation: returns inf in case of overflow
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@557 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r--NEWS3
-rw-r--r--src/norm.c7
-rw-r--r--tests/norm.dat2
3 files changed, 8 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 3325a30..f298e5e 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,8 @@
Recent Changes:
- New functions: mpc_pow
- Bug fixes:
- - log (along branch cut)
+ - log: along branch cut
+ - norm: infinite loop in case of overflow
- Makefile.vc updated (thanks to Mickael Gastineau)
- Minimal gmp version is 4.2
- Changed MPC_SET_X_Y macro
diff --git a/src/norm.c b/src/norm.c
index 28c8abe..4a66554 100644
--- a/src/norm.c
+++ b/src/norm.c
@@ -61,11 +61,12 @@ mpc_norm (mpfr_ptr a, mpc_srcptr b, mp_rnd_t rnd)
mpfr_set_prec (u, prec);
mpfr_set_prec (v, prec);
- /* first compute norm(b)^2 */
- inexact = mpfr_sqr (u, MPC_RE(b), GMP_RNDN); /* err<=1/2ulp */
+ inexact = mpfr_sqr (u, MPC_RE(b), GMP_RNDN); /* err<=1/2ulp */
inexact |= mpfr_sqr (v, MPC_IM(b), GMP_RNDN); /* err<=1/2ulp*/
+ inexact |= mpfr_add (u, u, v, GMP_RNDN); /* err <= 3/2 ulps */
- inexact |= mpfr_add (u, u, v, GMP_RNDN); /* err <= 3/2 ulps */
+ if (mpfr_inf_p (u))
+ inexact = 0;
}
while (inexact != 0 &&
mpfr_can_round (u, prec - 2, GMP_RNDN, rnd, MPFR_PREC(a)) == 0);
diff --git a/tests/norm.dat b/tests/norm.dat
index 47d7209..473550e 100644
--- a/tests/norm.dat
+++ b/tests/norm.dat
@@ -74,3 +74,5 @@
0 7 1 7 1 7 +0 N
0 7 2 7 1 7 1 N
+# overflow
+0 53 +inf 2 0x1p536870912 2 0x1p536870912 U