diff options
author | zimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2009-10-01 06:58:24 +0000 |
---|---|---|
committer | zimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2009-10-01 06:58:24 +0000 |
commit | e55440f353bede304ad4a392caa391668d66d741 (patch) | |
tree | 574e228967c64848f6352e849c5f2726b9e2833f /src/sqr.c | |
parent | 29754b106f78f82bc04117541cd3dba03d288878 (diff) | |
download | mpc-e55440f353bede304ad4a392caa391668d66d741.tar.gz |
[sqr.c] added asserts to check for overflow/underflow
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@691 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'src/sqr.c')
-rw-r--r-- | src/sqr.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -19,6 +19,7 @@ along with the MPC Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <stdio.h> /* for MPC_ASSERT */ #include "mpc-impl.h" int @@ -163,6 +164,8 @@ mpc_sqr (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) else if (mpfr_sgn (u) * mpfr_sgn (v) > 0) { inexact |= mpfr_mul (u, u, v, GMP_RNDU); /* error 5 */ + /* checks that no overflow nor underflow occurs */ + MPC_ASSERT (mpfr_inf_p (u) == 0 && mpfr_zero_p (u) == 0); 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) @@ -176,6 +179,8 @@ mpc_sqr (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) else { inexact |= mpfr_mul (u, u, v, GMP_RNDD); /* error 5 */ + /* checks that no overflow nor underflow occurs */ + MPC_ASSERT (mpfr_inf_p (u) == 0 && mpfr_zero_p (u) == 0); 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) @@ -190,6 +195,9 @@ mpc_sqr (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) /* compute the imaginary part as 2*x*y, which is always possible */ inex_im = mpfr_mul (MPC_IM (rop), x, MPC_IM (op), MPC_RND_IM (rnd)); + /* checks that no overflow nor underflow occurs */ + MPC_ASSERT (mpfr_inf_p (MPC_IM (rop)) == 0 && + mpfr_zero_p (MPC_IM (rop)) == 0); mpfr_mul_2ui (MPC_IM (rop), MPC_IM (rop), 1, GMP_RNDN); mpfr_clear (u); |