!File: spec_arith.h
/* describes internal compiler arithmetics */
#undef SPECIAL_ARITHMETICS /* something different from native long */
-/*#define UNSIGNED_ARITH unsigned arith /* if it is supported */
!File: static.h
!File: spec_arith.h
/* describes internal compiler arithmetics */
#undef SPECIAL_ARITHMETICS /* something different from native long */
-/*#define UNSIGNED_ARITH unsigned arith /* if it is supported */
!File: static.h
expr_warning(expr, "division by 0");
break;
}
- if (uns) {
-#ifdef UNSIGNED_ARITH
- o1 /= (UNSIGNED_ARITH) o2;
-#else
- /* this is more of a problem than you might
- think on C compilers which do not have
- unsigned arith (== long (probably)).
- */
- if (o2 & arith_sign) {/* o2 > max_arith */
- o1 = ! (o1 >= 0 || o1 < o2);
- /* this is the unsigned test
- o1 < o2 for o2 > max_arith
- */
- }
- else { /* o2 <= max_arith */
- arith half, bit, hdiv, hrem, rem;
-
- half = (o1 >> 1) & ~arith_sign;
- bit = o1 & 01;
- /* now o1 == 2 * half + bit
- and half <= max_arith
- and bit <= max_arith
- */
- hdiv = half / o2;
- hrem = half % o2;
- rem = 2 * hrem + bit;
- o1 = 2 * hdiv + (rem < 0 || rem >= o2);
- /* that is the unsigned compare
- rem >= o2 for o2 <= max_arith
- */
- }
-#endif
- }
+ if (uns)
+ o1 /= (unsigned arith) o2;
else
o1 /= o2;
break;
expr_warning(expr, "modulo by 0");
break;
}
- if (uns) {
-#ifdef UNSIGNED_ARITH
- o1 %= (UNSIGNED_ARITH) o2;
-#else
- if (o2 & arith_sign) {/* o2 > max_arith */
- o1 = (o1 >= 0 || o1 < o2) ? o1 : o1 - o2;
- /* this is the unsigned test
- o1 < o2 for o2 > max_arith
- */
- }
- else { /* o2 <= max_arith */
- arith half, bit, hrem, rem;
-
- half = (o1 >> 1) & ~arith_sign;
- bit = o1 & 01;
- /* now o1 == 2 * half + bit
- and half <= max_arith
- and bit <= max_arith
- */
- hrem = half % o2;
- rem = 2 * hrem + bit;
- o1 = (rem < 0 || rem >= o2) ? rem - o2 : rem;
- }
-#endif
- }
+ if (uns)
+ o1 %= (unsigned arith) o2;
else
o1 %= o2;
break;
}
/* Fall through */
case '>':
- if (uns) {
-#ifdef UNSIGNED_ARITH
- o1 = (UNSIGNED_ARITH) o1 > (UNSIGNED_ARITH) o2;
-#else
- o1 = (o1 & arith_sign ?
- (o2 & arith_sign ? o1 > o2 : 1) :
- (o2 & arith_sign ? 0 : o1 > o2)
- );
-#endif
- }
+ if (uns)
+ o1 = (unsigned arith) o1 > (unsigned arith) o2;
else
o1 = o1 > o2;
break;
}
/* Fall through */
case GREATEREQ:
- if (uns) {
-#ifdef UNSIGNED_ARITH
- o1 = (UNSIGNED_ARITH) o1 >= (UNSIGNED_ARITH) o2;
-#else
- o1 = (o1 & arith_sign ?
- (o2 & arith_sign ? o1 >= o2 : 1) :
- (o2 & arith_sign ? 0 : o1 >= o2)
- );
-#endif
- }
+ if (uns)
+ o1 = (unsigned arith) o1 >= (unsigned arith) o2;
else
o1 = o1 >= o2;
break;
break;
}
if (*pis_uns) {
-#ifdef UNSIGNED_ARITH
- *pval /= (UNSIGNED_ARITH) val;
-#else
- /* this is more of a problem than you might
- think on C compilers which do not have
- unsigned arith (== long (probably)).
- */
- if (val & arith_sign) {/* val > max_arith */
- *pval = ! (*pval >= 0 || *pval < val);
- /* this is the unsigned test
- *pval < val for val > max_arith
- */
- }
- else { /* val <= max_arith */
- arith half, bit, hdiv, hrem, rem;
-
- half = (*pval >> 1) & ~arith_sign;
- bit = *pval & 01;
- /* now *pval == 2 * half + bit
- and half <= max_arith
- and bit <= max_arith
- */
- hdiv = half / val;
- hrem = half % val;
- rem = 2 * hrem + bit;
- *pval = 2 * hdiv + (rem < 0 || rem >= val);
- /* that is the unsigned compare
- rem >= val for val <= max_arith
- */
- }
-#endif
+ *pval /= (unsigned arith) val;
}
else {
*pval = *pval / val;
break;
}
if (*pis_uns) {
-#ifdef UNSIGNED_ARITH
- *pval %= (UNSIGNED_ARITH) val;
-#else
- if (val & arith_sign) {/* val > max_arith */
- *pval = (*pval >= 0 || *pval < val) ? *pval : *pval - val;
- /* this is the unsigned test
- *pval < val for val > max_arith
- */
- }
- else { /* val <= max_arith */
- arith half, bit, hrem, rem;
-
- half = (*pval >> 1) & ~arith_sign;
- bit = *pval & 01;
- /* now *pval == 2 * half + bit
- and half <= max_arith
- and bit <= max_arith
- */
- hrem = half % val;
- rem = 2 * hrem + bit;
- *pval = (rem < 0 || rem >= val) ? rem - val : rem;
- }
-#endif
+ *pval %= (unsigned arith) val;
}
else {
*pval = *pval % val;
/* fall through */
case '>':
if (*pis_uns) {
-#ifdef UNSIGNED_ARITH
- *pval = (UNSIGNED_ARITH) *pval > (UNSIGNED_ARITH) val;
-#else
- *pval = (*pval & arith_sign ?
- (val & arith_sign ? *pval > val : 1) :
- (val & arith_sign ? 0 : *pval > val)
- );
-#endif
+ *pval = (unsigned arith) *pval > (unsigned arith) val;
}
else *pval = (*pval > val);
break;
/* fall through */
case GREATEREQ:
if (*pis_uns) {
-#ifdef UNSIGNED_ARITH
- *pval = (UNSIGNED_ARITH) *pval >= (UNSIGNED_ARITH) val;
-#else
- *pval = (*pval & arith_sign ?
- (val & arith_sign ? *pval >= val : 1) :
- (val & arith_sign ? 0 : *pval >= val)
- );
-#endif
+ *pval = (unsigned arith) *pval >= (unsigned arith) val;
}
else *pval = (*pval >= val);
break;