diff options
author | Kevin Ryde <user42@zip.com.au> | 2002-05-08 01:14:28 +0200 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2002-05-08 01:14:28 +0200 |
commit | 707d3ccd42d2c4407089bdc24ab7bd6ea619c9bb (patch) | |
tree | de5af9a82244732b8afc9e3d4e059b90a407a4fc /mpf/fits_u.h | |
parent | d19b9b19017f093abb5161227f32551e9f380567 (diff) | |
download | gmp-707d3ccd42d2c4407089bdc24ab7bd6ea619c9bb.tar.gz |
* mpf/fits_u.h, mpf/fits_s.h, tests/mpf/t-fits.c: Ignore fraction
part, making the code match the documentation.
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; } |