1 /* mpf_cmp_si -- Compare a float with a signed integer.
3 Copyright 1993-1995, 1999-2002, 2004, 2012, 2015 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 either:
11 * the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
17 * the GNU General Public License as published by the Free Software
18 Foundation; either version 2 of the License, or (at your option) any
21 or both in parallel, as here.
23 The GNU MP Library is distributed in the hope that it will be useful, but
24 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 You should have received copies of the GNU General Public License and the
29 GNU Lesser General Public License along with the GNU MP Library. If not,
30 see https://www.gnu.org/licenses/. */
36 mpf_cmp_si (mpf_srcptr u
, long int vval
) __GMP_NOTHROW
43 unsigned long abs_vval
;
47 /* 1. Are the signs different? */
48 if ((usize
< 0) == (vval
< 0)) /* don't use xor, type size may differ */
50 /* U and V are both non-negative or both negative. */
61 /* Either U or V is negative, but not both. */
62 return usize
>= 0 ? 1 : -1;
65 /* U and V have the same sign and are both non-zero. */
67 /* 2. Are the exponents different (V's exponent == 1)? */
69 usign
= usize
>= 0 ? 1 : -1;
71 abs_vval
= ABS_CAST (unsigned long, vval
);
73 #if GMP_NAIL_BITS != 0
74 if (uexp
!= 1 + (abs_vval
> GMP_NUMB_MAX
))
75 return (uexp
< 1 + (abs_vval
> GMP_NUMB_MAX
)) ? -usign
: usign
;
78 return (uexp
< 1) ? -usign
: usign
;
85 #if GMP_NAIL_BITS != 0
88 if ((ulimb
>> GMP_NAIL_BITS
) != 0)
90 ulimb
= (ulimb
<< GMP_NUMB_BITS
);
91 if (usize
!= 0) ulimb
|= up
[--usize
];
95 /* 3. Compare the most significant mantissa limb with V. */
96 if (ulimb
!= abs_vval
)
97 return (ulimb
< abs_vval
) ? -usign
: usign
;
99 /* Ignore zeroes at the low end of U. */
100 for (; *up
== 0; ++up
)
103 /* 4. Now, if the number of limbs are different, we have a difference
104 since we have made sure the trailing limbs are not zero. */
108 /* Wow, we got zero even if we tried hard to avoid it. */