summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mpf/fits_s.h45
-rw-r--r--mpf/fits_u.h44
2 files changed, 67 insertions, 22 deletions
diff --git a/mpf/fits_s.h b/mpf/fits_s.h
index afcdd266c..6f2318a0c 100644
--- a/mpf/fits_s.h
+++ b/mpf/fits_s.h
@@ -28,25 +28,46 @@ MA 02111-1307, USA. */
int
FUNCTION (mpf_srcptr f)
{
- int size, abs_size, i;
+ mp_size_t fs, fn, i;
+ mp_srcptr fp;
mp_exp_t exp;
- mp_srcptr ptr;
+ mp_limb_t fl;
- size = SIZ(f);
- if (size == 0)
- return 1; /* zero fits */
+ fs = SIZ(f);
+ if (fs == 0)
+ return 1;
exp = EXP(f);
- if (exp != 1) /* only 1 limb above the radix point */
+ fp = PTR(f);
+ fn = ABS (fs);
+
+ if (exp == 1)
+ {
+ fn -= 1; /* decrement to point at first fraction limb */
+ fl = fp[fn];
+ }
+#if GMP_NAIL_BITS != 0
+ else if (exp == 2 && MAXIMUM > GMP_NUMB_MAX)
+ {
+ fn -= 1;
+ fl = fp[fn];
+ if ((fl >> GMP_NAIL_BITS) != 0)
+ return 0;
+ fl = (fl << GMP_NUMB_BITS);
+ if (fn >= 1)
+ {
+ fn -= 1; /* decrement to point at first fraction limb */
+ fl |= fp[fn];
+ }
+ }
+#endif
+ else
return 0;
/* any fraction limbs must be zero */
- abs_size = ABS(size);
- ptr = PTR(f);
- for (i = 0; i < abs_size-1; i++)
- if (ptr[i] != 0)
+ for (i = fn - 1; i >= 0; i--)
+ if (fp[i] != 0)
return 0;
- return ptr[abs_size-1]
- <= (size > 0 ? (mp_limb_t) MAXIMUM : - (mp_limb_t) MINIMUM);
+ return fl <= (fs >= 0 ? (mp_limb_t) MAXIMUM : - (mp_limb_t) MINIMUM);
}
diff --git a/mpf/fits_u.h b/mpf/fits_u.h
index 439de39c1..d1d94583c 100644
--- a/mpf/fits_u.h
+++ b/mpf/fits_u.h
@@ -28,21 +28,45 @@ MA 02111-1307, USA. */
int
FUNCTION (mpf_srcptr f)
{
- int size, i;
- mp_srcptr ptr;
+ mp_size_t fn, i;
+ mp_srcptr fp;
+ mp_exp_t exp;
+ mp_limb_t fl;
- size = SIZ (f);
- if (size <= 0)
- return (size == 0); /* zero fits, negatives don't */
+ fn = SIZ(f);
+ if (fn <= 0)
+ return fn == 0; /* zero fits, negatives don't */
- if (EXP(f) != 1) /* only 1 limb above the radix point */
+ exp = EXP(f);
+ fp = PTR(f);
+
+ if (exp == 1)
+ {
+ fn -= 1; /* decrement to point at first fraction limb */
+ fl = fp[fn];
+ }
+#if GMP_NAIL_BITS != 0
+ else if (exp == 2 && MAXIMUM > GMP_NUMB_MAX)
+ {
+ fn -= 1;
+ fl = fp[fn];
+ if ((fl >> GMP_NAIL_BITS) != 0)
+ return 0;
+ fl = (fl << GMP_NUMB_BITS);
+ if (fn >= 1)
+ {
+ fn -= 1; /* decrement to point at first fraction limb */
+ fl |= fp[fn];
+ }
+ }
+#endif
+ else
return 0;
/* any fraction limbs must be zero */
- ptr = PTR (f);
- for (i = 0; i < size-1; i++)
- if (ptr[i] != 0)
+ for (i = fn - 1; i >= 0; i--)
+ if (fp[i] != 0)
return 0;
- return ptr[size-1] <= MAXIMUM;
+ return fl <= MAXIMUM;
}