+ long int in = SCM_INUM (n);
+ unsigned long int bits = iend - istart;
+
+ if (in < 0 && bits >= SCM_FIXNUM_BIT)
+ {
+ /* Since we emulate two's complement encoded numbers, this special
+ * case requires us to produce a result that has more bits than can be
+ * stored in a fixnum. Thus, we fall back to the more general
+ * algorithm that is used for bignums.
+ */
+ goto generalcase;
+ }
+
+ if (istart < SCM_FIXNUM_BIT)
+ {
+ in = in >> istart;
+ if (bits < SCM_FIXNUM_BIT)
+ return SCM_MAKINUM (in & ((1L << bits) - 1));
+ else /* we know: in >= 0 */
+ return SCM_MAKINUM (in);
+ }
+ else if (in < 0)
+ {
+ return SCM_MAKINUM (-1L & ((1L << bits) - 1));
+ }
+ else
+ {
+ return SCM_MAKINUM (0);
+ }