summaryrefslogtreecommitdiff
path: root/add_ui.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2001-10-19 20:45:12 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2001-10-19 20:45:12 +0000
commit86119813a1a31bf82ac49fc4e24c29127984004e (patch)
tree8d34098cc013bf8507ea4084b0da3e4d7ce5c419 /add_ui.c
parent7a437b5132ff0ee27c2b135675f64fa74012424d (diff)
downloadmpfr-86119813a1a31bf82ac49fc4e24c29127984004e.tar.gz
Bugs fixed concerning the "inexact" ternary value.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1324 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'add_ui.c')
-rw-r--r--add_ui.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/add_ui.c b/add_ui.c
index 0e1ebbe5c..88d98d0e5 100644
--- a/add_ui.c
+++ b/add_ui.c
@@ -37,13 +37,14 @@ mpfr_add_ui (y, x, u, rnd_mode)
mp_rnd_t rnd_mode;
#endif
{
- mpfr_t uu;
- mp_limb_t up[1];
- unsigned long cnt;
- int inexact;
if (u) /* if u=0, do nothing */
{
+ mpfr_t uu;
+ mp_limb_t up[1];
+ unsigned long cnt;
+ int inex_add, inex_cr;
+
MPFR_INIT1(up, uu, BITS_PER_MP_LIMB, 1);
count_leading_zeros(cnt, (mp_limb_t) u);
*up = (mp_limb_t) u << cnt;
@@ -52,10 +53,12 @@ mpfr_add_ui (y, x, u, rnd_mode)
/* Optimization note: Exponent operations may be removed
if mpfr_add works even when uu is out-of-range. */
mpfr_save_emin_emax();
- inexact = mpfr_add(y, x, uu, rnd_mode);
- mpfr_restore_emin_emax();
- mpfr_check_range(y, rnd_mode);
- return inexact;
+ inex_add = mpfr_add(y, x, uu, rnd_mode);
+ mpfr_restore_emin_emax(); /* flags are restored too */
+ inex_cr = mpfr_check_range(y, rnd_mode);
+ if (inex_cr)
+ return inex_cr; /* underflow or overflow */
+ MPFR_RET(inex_add);
}
else
return mpfr_set (y, x, rnd_mode);