summaryrefslogtreecommitdiff
path: root/get_ui.c
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-09-29 12:27:36 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-09-29 12:27:36 +0000
commit8eb22ba63830dbf829b9faa742c68438c43992d9 (patch)
tree3482ee8bed089b988aae3d20dda76cede0dab587 /get_ui.c
parent795c8ef5f9daa924b5592582240c9ba9a58034c1 (diff)
downloadmpfr-8eb22ba63830dbf829b9faa742c68438c43992d9.tar.gz
Add mpfr_clear_erangeflag and mpfr_erangeflag_p.
Add test for theses two functions. mpfr_get_[s/u][i/j] have a deterministic behavior in case of OVERFLOW. (Return the MINIMUM or the MAXIMUM in the current type, and set ERANGE_flag). git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@3007 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'get_ui.c')
-rw-r--r--get_ui.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/get_ui.c b/get_ui.c
index 1d5d286d0..cd238b9a5 100644
--- a/get_ui.c
+++ b/get_ui.c
@@ -19,7 +19,7 @@ along with the MPFR 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 <limits.h>
#include "mpfr-impl.h"
unsigned long
@@ -31,7 +31,13 @@ mpfr_get_ui (mpfr_srcptr f, mp_rnd_t rnd)
mp_size_t n;
mp_exp_t exp;
- if (!mpfr_fits_ulong_p (f, rnd) || MPFR_IS_ZERO(f))
+ if (!mpfr_fits_ulong_p (f, rnd))
+ {
+ MPFR_SET_ERANGE ();
+ return MPFR_IS_NEG (f) ? 0 : ULONG_MAX;
+ }
+
+ if (MPFR_IS_ZERO (f))
return (unsigned long) 0;
for (s = ULONG_MAX, prec = 0; s != 0; s >>= 1, prec ++);