github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/mpf/fits_u.h (about) 1 /* mpf_fits_u*_p -- test whether an mpf fits a C unsigned type. 2 3 Copyright 2001, 2002, 2013, 2014 Free Software Foundation, Inc. 4 5 This file is part of the GNU MP Library. 6 7 The GNU MP Library is free software; you can redistribute it and/or modify 8 it under the terms of either: 9 10 * the GNU Lesser General Public License as published by the Free 11 Software Foundation; either version 3 of the License, or (at your 12 option) any later version. 13 14 or 15 16 * the GNU General Public License as published by the Free Software 17 Foundation; either version 2 of the License, or (at your option) any 18 later version. 19 20 or both in parallel, as here. 21 22 The GNU MP Library is distributed in the hope that it will be useful, but 23 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 24 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 for more details. 26 27 You should have received copies of the GNU General Public License and the 28 GNU Lesser General Public License along with the GNU MP Library. If not, 29 see https://www.gnu.org/licenses/. */ 30 31 #include "gmp.h" 32 #include "gmp-impl.h" 33 34 35 /* Notice this is equivalent to mpz_set_f + mpz_fits_u*_p. */ 36 37 int 38 FUNCTION (mpf_srcptr f) __GMP_NOTHROW 39 { 40 mp_size_t fn; 41 mp_srcptr fp; 42 mp_exp_t exp; 43 mp_limb_t fl; 44 45 exp = EXP(f); 46 if (exp < 1) 47 return 1; /* -1 < f < 1 truncates to zero, so fits */ 48 49 fn = SIZ(f); 50 if (fn < 0) /* zero catched by exp == 0 */ 51 return 0; /* negatives don't fit */ 52 53 fp = PTR(f); 54 55 if (exp == 1) 56 { 57 fl = fp[fn-1]; 58 } 59 #if GMP_NAIL_BITS != 0 60 else if (exp == 2 && MAXIMUM > GMP_NUMB_MAX) 61 { 62 fl = fp[fn-1]; 63 if ((fl >> GMP_NAIL_BITS) != 0) 64 return 0; 65 fl = (fl << GMP_NUMB_BITS); 66 if (fn >= 2) 67 fl |= fp[fn-2]; 68 } 69 #endif 70 else 71 return 0; 72 73 return fl <= MAXIMUM; 74 }