diff options
author | Paul Zimmermann <Paul.Zimmermann@inria.fr> | 2015-04-09 12:40:12 +0200 |
---|---|---|
committer | Paul Zimmermann <Paul.Zimmermann@inria.fr> | 2015-04-09 12:40:12 +0200 |
commit | be209c946a7aa5082ac5a9e194a150e481e6954e (patch) | |
tree | a6f7e498db77f6ef7c10f4263d376317e367134a | |
parent | 72edb3d5f0e38d0e0dbc272807175f6cacba592b (diff) | |
download | mpc-git-be209c946a7aa5082ac5a9e194a150e481e6954e.tar.gz |
fixed overflow issue in mpc_exp with rounding towards zero
-rw-r--r-- | src/exp.c | 4 | ||||
-rw-r--r-- | src/mpc-impl.h | 1 | ||||
-rw-r--r-- | src/sin_cos.c | 12 |
3 files changed, 9 insertions, 8 deletions
@@ -180,8 +180,8 @@ mpc_exp (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) inex_im = mpfr_set (mpc_imagref(rop), z, MPC_RND_IM(rnd)); if (mpfr_overflow_p ()) { /* overflow in real exponential, inex is sign of infinite result */ - inex_re = mpfr_sgn (y); - inex_im = mpfr_sgn (z); + inex_re = mpc_fix_inf (mpc_realref(rop), MPC_RND_RE(rnd)); + inex_im = mpc_fix_inf (mpc_imagref(rop), MPC_RND_IM(rnd)); } else if (mpfr_underflow_p ()) { /* underflow in real exponential, inex is opposite of sign of 0 result */ diff --git a/src/mpc-impl.h b/src/mpc-impl.h index 330833f..b585007 100644 --- a/src/mpc-impl.h +++ b/src/mpc-impl.h @@ -161,6 +161,7 @@ __MPC_DECLSPEC char* mpc_realloc_str (char*, size_t, size_t); __MPC_DECLSPEC void mpc_free_str (char*); __MPC_DECLSPEC mpfr_prec_t mpc_ceil_log2 (mpfr_prec_t); __MPC_DECLSPEC int set_pi_over_2 (mpfr_ptr, int, mpfr_rnd_t); +__MPC_DECLSPEC int mpc_fix_inf (mpfr_t x, mpfr_rnd_t rnd); #if defined (__cplusplus) } diff --git a/src/sin_cos.c b/src/sin_cos.c index fb6fc7a..24e412b 100644 --- a/src/sin_cos.c +++ b/src/sin_cos.c @@ -270,8 +270,8 @@ mpc_sin_cos_imag (mpc_ptr rop_sin, mpc_ptr rop_cos, mpc_srcptr op, When rnd is towards zero, change x into the largest (in absolute value) floating-point number. Return the inexact flag. */ -static int -fix_inf (mpfr_t x, mpfr_rnd_t rnd) +int +mpc_fix_inf (mpfr_t x, mpfr_rnd_t rnd) { if (!MPC_IS_LIKE_RNDZ(rnd, MPFR_SIGNBIT(x))) return mpfr_sgn (x); @@ -405,10 +405,10 @@ mpc_sin_cos (mpc_ptr rop_sin, mpc_ptr rop_cos, mpc_srcptr op, if (rop_sin != NULL) { inex_re = mpfr_set (mpc_realref (rop_sin), sch, MPC_RND_RE (rnd_sin)); if (mpfr_inf_p (sch)) - inex_re = fix_inf (mpc_realref (rop_sin), MPC_RND_RE (rnd_sin)); + inex_re = mpc_fix_inf (mpc_realref (rop_sin), MPC_RND_RE (rnd_sin)); inex_im = mpfr_set (mpc_imagref (rop_sin), csh, MPC_RND_IM (rnd_sin)); if (mpfr_inf_p (csh)) - inex_im = fix_inf (mpc_imagref (rop_sin), MPC_RND_IM (rnd_sin)); + inex_im = mpc_fix_inf (mpc_imagref (rop_sin), MPC_RND_IM (rnd_sin)); inex_sin = MPC_INEX (inex_re, inex_im); } else @@ -417,10 +417,10 @@ mpc_sin_cos (mpc_ptr rop_sin, mpc_ptr rop_cos, mpc_srcptr op, if (rop_cos != NULL) { inex_re = mpfr_set (mpc_realref (rop_cos), c, MPC_RND_RE (rnd_cos)); if (mpfr_inf_p (c)) - inex_re = fix_inf (mpc_realref (rop_cos), MPC_RND_RE (rnd_cos)); + inex_re = mpc_fix_inf (mpc_realref (rop_cos), MPC_RND_RE (rnd_cos)); inex_im = mpfr_set (mpc_imagref (rop_cos), s, MPC_RND_IM (rnd_cos)); if (mpfr_inf_p (s)) - inex_im = fix_inf (mpc_imagref (rop_cos), MPC_RND_IM (rnd_cos)); + inex_im = mpc_fix_inf (mpc_imagref (rop_cos), MPC_RND_IM (rnd_cos)); inex_cos = MPC_INEX (inex_re, inex_im); } else |