1 /* mpf_cmp_ui -- Compare a float with an unsigned integer.
3 Copyright 1993-1995, 1999, 2001, 2002, 2015 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of either:
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.
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
20 or both in parallel, as here.
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
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/. */
35 mpf_cmp_ui (mpf_srcptr u
, unsigned long int vval
) __GMP_NOTHROW
44 /* 1. Is U negative? */
47 /* We rely on usize being non-negative in the code that follows. */
52 /* 2. Are the exponents different (V's exponent == 1)? */
55 #if GMP_NAIL_BITS != 0
56 if (uexp
!= 1 + (vval
> GMP_NUMB_MAX
))
57 return (uexp
< 1 + (vval
> GMP_NUMB_MAX
)) ? -1 : 1;
60 return (uexp
< 1) ? -1 : 1;
67 #if GMP_NAIL_BITS != 0
70 if ((ulimb
>> GMP_NAIL_BITS
) != 0)
72 ulimb
= (ulimb
<< GMP_NUMB_BITS
);
73 if (usize
!= 0) ulimb
|= up
[--usize
];
77 /* 3. Compare the most significant mantissa limb with V. */
79 return (ulimb
< vval
) ? -1 : 1;
81 /* Ignore zeroes at the low end of U. */
82 for (; *up
== 0; ++up
)
85 /* 4. Now, if the number of limbs are different, we have a difference
86 since we have made sure the trailing limbs are not zero. */