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
) __GMP_NOTHROW
32 unsigned long abs_vval
;
37 /* 1. Are the signs different? */
38 if ((usize
< 0) == (vval
< 0)) /* don't use xor, type size may differ */
40 /* U and V are both non-negative or both negative. */
51 /* Either U or V is negative, but not both. */
52 return usize
>= 0 ? 1 : -1;
55 /* U and V have the same sign and are both non-zero. */
57 usign
= usize
>= 0 ? 1 : -1;
59 abs_vval
= ABS_CAST (unsigned long, vval
);
61 /* 2. Are the exponents different (V's exponent == 1)? */
62 #if GMP_NAIL_BITS != 0
63 if (uexp
> 1 + (abs_vval
> GMP_NUMB_MAX
))
65 if (uexp
< 1 + (abs_vval
> GMP_NUMB_MAX
))
76 ulimb
= up
[usize
- 1];
77 #if GMP_NAIL_BITS != 0
78 if (usize
>= 2 && uexp
== 2)
80 if ((ulimb
>> GMP_NAIL_BITS
) != 0)
82 ulimb
= (ulimb
<< GMP_NUMB_BITS
) | up
[usize
- 2];
88 /* 3. Compare the most significant mantissa limb with V. */
91 else if (ulimb
< abs_vval
)
94 /* Ignore zeroes at the low end of U. */
101 /* 4. Now, if the number of limbs are different, we have a difference
102 since we have made sure the trailing limbs are not zero. */
106 /* Wow, we got zero even if we tried hard to avoid it. */