diff options
Diffstat (limited to 'mpf/fits_u.h')
-rw-r--r-- | mpf/fits_u.h | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/mpf/fits_u.h b/mpf/fits_u.h index d1d94583c..640f45193 100644 --- a/mpf/fits_u.h +++ b/mpf/fits_u.h @@ -1,6 +1,6 @@ /* mpf_fits_u*_p -- test whether an mpf fits a C unsigned type. -Copyright 2001 Free Software Foundation, Inc. +Copyright 2001, 2002 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -28,7 +28,7 @@ MA 02111-1307, USA. */ int FUNCTION (mpf_srcptr f) { - mp_size_t fn, i; + mp_size_t fn; mp_srcptr fp; mp_exp_t exp; mp_limb_t fl; @@ -38,35 +38,28 @@ FUNCTION (mpf_srcptr f) return fn == 0; /* zero fits, negatives don't */ exp = EXP(f); + if (exp < 1) + return 1; /* 0 < f < 1 truncates to zero, so fits */ + fp = PTR(f); if (exp == 1) { - fn -= 1; /* decrement to point at first fraction limb */ - fl = fp[fn]; + fl = fp[fn-1]; } #if GMP_NAIL_BITS != 0 else if (exp == 2 && MAXIMUM > GMP_NUMB_MAX) { - fn -= 1; - fl = fp[fn]; + fl = fp[fn-1]; if ((fl >> GMP_NAIL_BITS) != 0) return 0; fl = (fl << GMP_NUMB_BITS); - if (fn >= 1) - { - fn -= 1; /* decrement to point at first fraction limb */ - fl |= fp[fn]; - } + if (fn >= 2) + fl |= fp[fn-2]; } #endif else return 0; - /* any fraction limbs must be zero */ - for (i = fn - 1; i >= 0; i--) - if (fp[i] != 0) - return 0; - return fl <= MAXIMUM; } |