1 /* mpf_cmp_si -- Compare a float with a signed integer.
3 Copyright 1993, 1994, 1995, 1999, 2000, 2001, 2002, 2004 Free Software
6 This file is part of the GNU MP Library.
8 The GNU MP Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
13 The GNU MP Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
25 mpf_cmp_si (mpf_srcptr u, long int vval)
36 /* 1. Are the signs different? */
37 if ((usize < 0) == (vval < 0)) /* don't use xor, type size may differ */
39 /* U and V are both non-negative or both negative. */
50 /* Either U or V is negative, but not both. */
51 return usize >= 0 ? 1 : -1;
54 /* U and V have the same sign and are both non-zero. */
56 usign = usize >= 0 ? 1 : -1;
60 /* 2. Are the exponents different (V's exponent == 1)? */
61 #if GMP_NAIL_BITS != 0
62 if (uexp > 1 + ((unsigned long) vval > GMP_NUMB_MAX))
64 if (uexp < 1 + ((unsigned long) vval > GMP_NUMB_MAX))
75 ulimb = up[usize - 1];
76 #if GMP_NAIL_BITS != 0
77 if (usize >= 2 && uexp == 2)
79 if ((ulimb >> GMP_NAIL_BITS) != 0)
81 ulimb = (ulimb << GMP_NUMB_BITS) | up[usize - 2];
87 /* 3. Compare the most significant mantissa limb with V. */
88 if (ulimb > (unsigned long) vval)
90 else if (ulimb < (unsigned long) vval)
93 /* Ignore zeroes at the low end of U. */
100 /* 4. Now, if the number of limbs are different, we have a difference
101 since we have made sure the trailing limbs are not zero. */
105 /* Wow, we got zero even if we tried hard to avoid it. */