diff options
author | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-09-29 12:27:36 +0000 |
---|---|---|
committer | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-09-29 12:27:36 +0000 |
commit | 8eb22ba63830dbf829b9faa742c68438c43992d9 (patch) | |
tree | 3482ee8bed089b988aae3d20dda76cede0dab587 /get_sj.c | |
parent | 795c8ef5f9daa924b5592582240c9ba9a58034c1 (diff) | |
download | mpfr-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_sj.c')
-rw-r--r-- | get_sj.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -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,14 @@ mpfr_get_sj (mpfr_srcptr f, mpfr_rnd_t rnd) mp_prec_t prec; mpfr_t x; + if (!mpfr_fits_intmax_p (f, rnd)) + { + MPFR_SET_ERANGE (); + return MPFR_IS_NEG (f) ? INTMAX_MIN : INTMAX_MAX; + } + if (MPFR_IS_ZERO (f)) + return (intmax_t) 0; + /* determine the precision of intmax_t */ for (r = INTMAX_MIN, prec = 0; r != 0; r /= 2, prec++) { @@ -63,8 +78,9 @@ mpfr_get_sj (mpfr_srcptr f, mpfr_rnd_t rnd) xp = MPFR_MANT (x); sh = MPFR_GET_EXP (x); - MPFR_ASSERTN (sh <= prec); - if (INTMAX_MIN + INTMAX_MAX != 0 && MPFR_UNLIKELY (sh == prec)) + MPFR_ASSERTN ((mp_prec_t) sh <= prec); + if (INTMAX_MIN + INTMAX_MAX != 0 + && MPFR_UNLIKELY ((mp_prec_t) sh == prec)) { /* 2's complement and x <= INTMAX_MIN: in the case mp_limb_t has the same size as intmax_t, we cannot use the code in |