summaryrefslogtreecommitdiff
path: root/get_uj.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_uj.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_uj.c')
-rw-r--r--get_uj.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/get_uj.c b/get_uj.c
index 34b700eef..1d1e29042 100644
--- a/get_uj.c
+++ b/get_uj.c
@@ -23,6 +23,13 @@ MA 02111-1307, USA. */
# include "config.h" /* for a build within gmp */
#endif
+/* The ISO C99 standard specifies that in C++ implementations the
+ INTMAX_MAX, ... macros should only be defined if explicitly requested. */
+#if defined __cplusplus
+# define __STDC_LIMIT_MACROS
+# define __STDC_CONSTANT_MACROS
+#endif
+
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
@@ -41,6 +48,15 @@ mpfr_get_uj (mpfr_srcptr f, mpfr_rnd_t rnd)
mp_prec_t prec;
mpfr_t x;
+ if (!mpfr_fits_uintmax_p (f, rnd))
+ {
+ MPFR_SET_ERANGE ();
+ return MPFR_IS_NEG (f) ? (uintmax_t) 0 : UINTMAX_MAX;
+ }
+
+ if (MPFR_IS_ZERO (f))
+ return (uintmax_t) 0;
+
/* determine the precision of uintmax_t */
for (r = UINTMAX_MAX, prec = 0; r != 0; r /= 2, prec++)
{ }
@@ -59,7 +75,7 @@ mpfr_get_uj (mpfr_srcptr f, mpfr_rnd_t rnd)
MPFR_ASSERTN (MPFR_IS_POS (x));
xp = MPFR_MANT (x);
sh = MPFR_GET_EXP (x);
- MPFR_ASSERTN (sh <= prec);
+ MPFR_ASSERTN ((mp_prec_t) sh <= prec);
for (n = MPFR_LIMB_SIZE(x) - 1; n >= 0; n--)
{
sh -= BITS_PER_MP_LIMB;