summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2012-06-26 15:09:15 +0000
committerzimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2012-06-26 15:09:15 +0000
commit27e679c97fe25163ca1a21e5443916636b8ea729 (patch)
treec4fcff99f54c25d657345723c2a5a85a2fc2bdde
parentfcc0f3529b397cddd67eda85c751085e79dc3922 (diff)
downloadmpc-27e679c97fe25163ca1a21e5443916636b8ea729.tar.gz
[tatan.c] added one test to improve the code coverage, which produces an
infinite loop in mpc_atan... [atan.c] added a check to detect potential infinite loops git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@1167 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r--src/atan.c6
-rw-r--r--tests/tatan.c31
2 files changed, 35 insertions, 2 deletions
diff --git a/src/atan.c b/src/atan.c
index fb0f067..3177a45 100644
--- a/src/atan.c
+++ b/src/atan.c
@@ -1,6 +1,6 @@
/* mpc_atan -- arctangent of a complex number.
-Copyright (C) 2009, 2010, 2011 INRIA
+Copyright (C) 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see http://www.gnu.org/licenses/ .
*/
+#include <stdio.h>
#include "mpc-impl.h"
/* set rop to
@@ -195,6 +196,7 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpfr_t minus_op_re;
mpfr_exp_t op_re_exp, op_im_exp;
mpfr_rnd_t rnd1, rnd2;
+ int loops = 0;
mpfr_inits2 (MPFR_PREC_MIN, a, b, x, y, (mpfr_ptr) 0);
@@ -230,6 +232,8 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
do
{
+ MPC_ASSERT (++loops < 100);
+
p += mpc_ceil_log2 (p) + 2;
mpfr_set_prec (a, p);
mpfr_set_prec (b, p);
diff --git a/tests/tatan.c b/tests/tatan.c
index b46f694..89e476e 100644
--- a/tests/tatan.c
+++ b/tests/tatan.c
@@ -1,6 +1,6 @@
/* tatan -- test file for mpc_atan.
-Copyright (C) 2009 INRIA
+Copyright (C) 2009, 2012 INRIA
This file is part of GNU MPC.
@@ -20,6 +20,33 @@ along with this program. If not, see http://www.gnu.org/licenses/ .
#include "mpc-tests.h"
+static int
+test_coverage (void)
+{
+ mpc_t z;
+ mpfr_exp_t emin = mpfr_get_emin ();
+
+ mpfr_set_emin (-10);
+ mpc_init2 (z, 21);
+ mpfr_set_si (mpc_realref(z), -1, GMP_RNDZ);
+ mpfr_set_ui_2exp (mpc_imagref(z), 1, 20, GMP_RNDZ);
+ mpfr_add_ui (mpc_imagref(z), mpc_imagref(z), 1, GMP_RNDZ);
+ mpfr_div_2exp (mpc_imagref(z), mpc_imagref(z), 20, GMP_RNDZ);
+ mpc_atan (z, z, MPC_RNDNN);
+ if (mpfr_cmp_si_2exp (mpc_realref(z), -1066635, 20) != 0 ||
+ mpfr_cmp_si_2exp (mpc_imagref(z), 1687619, 22))
+ {
+ printf ("Error in test_coverage\n");
+ printf ("expected (-1066635/2^20 1687619/2^22)\n");
+ printf ("got ");
+ mpc_out_str (stdout, 10, 20, z, MPC_RNDNN);
+ printf ("\n");
+ exit (1);
+ }
+ mpc_clear (z);
+ mpfr_set_emin (emin);
+}
+
int
main (void)
{
@@ -27,6 +54,8 @@ main (void)
test_start ();
+ test_coverage ();
+
data_check (f, "atan.dat");
tgeneric (f, 2, 512, 5, 128);