diff options
author | Kevin Ryde <user42@zip.com.au> | 2001-10-01 23:43:13 +0200 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2001-10-01 23:43:13 +0200 |
commit | c36d10a3e7425c13c46b1922edab8bacbfc36177 (patch) | |
tree | 5395cd68c887d947fa7cd6461ca5545bf0b669d1 /mpf | |
parent | adb7a358858693dc2d5c80f979be53d76e51e8b2 (diff) | |
download | gmp-c36d10a3e7425c13c46b1922edab8bacbfc36177.tar.gz |
* mpf/fits_s.i: Renamed and adapted from mpf/fits_s.c.
Diffstat (limited to 'mpf')
-rw-r--r-- | mpf/fits_s.i | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/mpf/fits_s.i b/mpf/fits_s.i new file mode 100644 index 000000000..afcdd266c --- /dev/null +++ b/mpf/fits_s.i @@ -0,0 +1,52 @@ +/* mpf_fits_s*_p -- test whether an mpf fits a C signed type. + +Copyright 2001 Free Software Foundation, Inc. + +This file is part of the GNU MP Library. + +The GNU MP Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The GNU MP Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MP 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 "gmp.h" +#include "gmp-impl.h" + + +/* Notice this is equivalent to mpz_set_f + mpz_fits_s*_p. */ + +int +FUNCTION (mpf_srcptr f) +{ + int size, abs_size, i; + mp_exp_t exp; + mp_srcptr ptr; + + size = SIZ(f); + if (size == 0) + return 1; /* zero fits */ + + exp = EXP(f); + if (exp != 1) /* only 1 limb above the radix point */ + return 0; + + /* any fraction limbs must be zero */ + abs_size = ABS(size); + ptr = PTR(f); + for (i = 0; i < abs_size-1; i++) + if (ptr[i] != 0) + return 0; + + return ptr[abs_size-1] + <= (size > 0 ? (mp_limb_t) MAXIMUM : - (mp_limb_t) MINIMUM); +} |