diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2007-01-20 13:45:20 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2007-01-20 13:45:20 +0000 |
commit | aa020031f73a5afad200b0c6b12db9a9a716b787 (patch) | |
tree | 6ce212ff33a012c9ca8074f3dc7c7bfd78471bd7 /set_si_2exp.c | |
parent | 2333ddd1383458a2fc880963da7fdefe9953b5f2 (diff) | |
download | mpfr-aa020031f73a5afad200b0c6b12db9a9a716b787.tar.gz |
Fixed mpfr_set_si_2exp in case of overflow or underflow.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@4346 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'set_si_2exp.c')
-rw-r--r-- | set_si_2exp.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/set_si_2exp.c b/set_si_2exp.c index 452a922ff..9be427e5c 100644 --- a/set_si_2exp.c +++ b/set_si_2exp.c @@ -20,17 +20,25 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include <limits.h> #include "mpfr-impl.h" int mpfr_set_si_2exp (mpfr_ptr x, long i, mp_exp_t e, mp_rnd_t rnd_mode) { + mpfr_t ii; int res; MPFR_SAVE_EXPO_DECL (expo); MPFR_SAVE_EXPO_MARK (expo); - res = mpfr_set_si (x, i, rnd_mode); - mpfr_mul_2si (x, x, e, rnd_mode); /* Should be exact */ + mpfr_init2 (ii, sizeof (long) * CHAR_BIT); + res = mpfr_set_si (ii, i, rnd_mode); /* exact, no exceptions */ + MPFR_ASSERTN (res == 0); + MPFR_ASSERTN (e >= LONG_MIN && e <= LONG_MAX); + /* FIXME: this may no longer be the case in the future. */ + res = mpfr_mul_2si (x, ii, e, rnd_mode); + mpfr_clear (ii); + MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags); MPFR_SAVE_EXPO_FREE (expo); res = mpfr_check_range(x, res, rnd_mode); return res; |